Ajax request differentiation $ _ server [''http _ x_requested_with ''] Small Solution

Source: Internet
Author: User

Many templates Code We all think that PHP has such a custom variable: $ _ server ['HTTP _ x_requested_with ']. In fact, this is not the case at all.
$ _ Server is an array containing header information, path, and script locations.

Some header information exists in the system and cannot be changed, such as host and user_agent. Note that we often use $ _ server ['HTTP _ host'], $ _ server ['HTTP _ user_agent '], which has an HTTP prefix. In this case, there is no HTTP prefix in the header information, and the information name is only host or the like, $ _ server automatically adds an HTTP prefix to them. 1 is to prevent conflicts with other information, and 2 is to indicate that they are header information. therefore, all the variables in $ _ server with an HTTP prefix are header information, but none are available, for example, $ _ server ['query _ string']. $ _ server ['php _ Self '] and so on.

You can create custom header information and send the information to the server. The server records the header information and stores them in the $ _ server variable, of course, the variable name is changed to "HTTP _" connected to the user's variable name. for example, the above Ajax request is judged. in fact, before sending an asynchronous request to the server, add a header to the header. The actual statement should be:

Httprequest object. setRequestHeader ("x_requested_with", "arbitrary string"); whether the server exists through $ _ server ['HTTP _ x_requested_with, or a specific value to determine whether it is an Ajax request or which Ajax request is required. therefore, this not only verifies whether the request is an Ajax request, but also obtains more information.

We can also set any other information in the header for data exchange with the server.

For example, XMLHttpRequest. setRequestHeader ("test", "just a test"); then the value of the variable $ _ server ['HTTP _ test'] on the requested Server Page is "just a test "; note that the test in front of it is not case sensitive. $ _ server ['HTTP _ test'] must be capitalized.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

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.