AJAX requests differentiate $_server[' Http_x_requested_with '] pee _ajax related
Source: Internet
Author: User
Influenced by a lot of template code, everyone thought PHP had such a custom variable: $_server[' Http_x_requested_with '. That's not really the case at all.
$_server is an array that contains information such as header (header), path (path), and script location (scripts locations). This is the exact words of the PHP manual.
There are some header information that exists in the system itself and cannot be changed, such as host,user_agent and so on, and notice what we often use is $_server[' http_host '],$_server[' http_user_agent '. Here all have HTTP prefix, implementation in header information inside there is no HTTP prefix, information name is only host and so on, $_server automatically add HTTP prefix for them, 1 is to prevent with its own other information conflict, 2 is to indicate that they are headers header information. So the variables in the $_server are all header information with HTTP prefixes, none of which is not, such as: $_server[' query_string ', $_server[' php_self ' Wait.
Users can create custom header headers and send that information to the server side, which will record the header information and store them in the $_server variable, and the variable name that is implemented becomes the variable name of the user on the "http_" link. Like above. Determine the AJAX request. In effect, before sending an asynchronous request to the server, a header message is added to the header, and the actual statement should be:
HttpRequest object. setRequestHeader ("X_requested_with", "arbitrary string"), and whether the server side is present through $_server[' Http_x_requested_with '. or a specific value to determine whether it is an AJAX request or a specific AJAX request. So use this not only to verify that the request is an AJAX request, but also to get more information.
Similarly, we can set any other information in the header to communicate with the server side.
For example: Xmlhttprequest.setrequestheader ("Test", "just a Test"); The value of the variable $_server[' http_test ' in the requested server page is "just a TEST"; Note that the TEST in front of this face is not fixed case. The $_server[' http_test ' must be in uppercase.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.