Php Tutorial verification request page source
If ($ _ server ['http _ x_requested_with '] = 'xmlhttprequest '){
Echo 'Ajax ';
} Else {
Echo 'normal ';
}
When jquery implements ajax internally, the ID has been added.
In jquery source code:
Xhr. setrequestheader ("x-requested-with", "xmlhttprequest ");
Therefore, you can use http_x_requested_with in php to determine whether to implement it separately :)
See the principles below
<Strong> when sending an ajax request, we can use the xmlhttprequest object to create
Defined header information </strong>
If you are using a native ajax method, that is, ajax that is not packaged using jquery or other js frameworks
The code is as follows:
Xmlhttprequest. setrequestheader ("request_type", "ajax ");
With jquery's $. ajax () method, you can easily create a custom
Header information.
$. Ajax ({
Type: "get ",
Url: base_url +
'Php _ check_ajax_request/get_user_list.html ',
Beforesend: function (xmlhttprequest ){
Xmlhttprequest. setrequestheader ("request_type", "ajax ");
},
Success: function (data ){
$ ("# User_list" ).html (data );
$ Tip. hide ();
$ Button. attr ('disabled ', true );
}
});
When getting it in php
If (isset ($ _ server ['http _ request_type ']) & $ _ server ['http _ request_type']
= "Ajax") {// ajax submit
} Else {// non-ajax commit
}