How can I tell if a request is an AJAX request?
1, we can use the HTTP protocol header information in the X-requested-with to judge
2, if the AJAX request is done using jquery, there will be a Http-x-requested-with key value in $_server, which can be used to judge
Such as:
if ($_server[' http_x_requested_with ' = = ' XMLHttpRequest ') { $username = isset ($_post[' username '])? Addslashes ($_ post[' username '): '; $passwd = isset ($_post[' passwd ')? Addslashes ($_post[' passwd '): '; if ($username = = ' LH ' && $passwd = = ' passwd ') { echo ' Hello baidu! '; }} else{ echo ' You must use Ajax request! ';}
If it was an AJAX request, what would be the referer of the request header information?
If it is an AJAX request, the Referer parameter corresponding to the request header information is the URL of the current page
The above describes how to judge a request for an AJAX request? , including the aspects of the content, want to be interested in PHP tutorial friends helpful.