The example in this article describes the way PHP is judged to be an AJAX request. Share to everyone for your reference, specific as follows:
First of all, how to distinguish the front end using JQuery:
When JQuery makes an AJAX request, it adds a message named X-requested-with to the request header, which reads: XMLHttpRequest
You can use $_server["Http_x_requested_with" on the back end to get it. (Note: The underscore is underlined, case-insensitive)
From this, we can determine whether the AJAX request:
if (Isset ($_server["Http_x_requested_with"]) && strtolower ($_server["Http_x_requested_with"]) = = " XMLHttpRequest ") {
//Ajax request processing mode
}else{
//Normal request processing mode
};
When Ajax requests are made using native JavaScript, we can also add information to the head to make it easier for the back-end students to distinguish between the following methods:
var xmlhttp=new xmlhttprequest ();
Xmlhttp.open ("Get", "test.php", true);
Xmlhttp.setrequestheader ("X-requested-with", "XMLHttpRequest");
Xmlhttp.send ();
For more information about PHP interested readers can view the site topics: "Php+ajax Skills and Application Summary", "PHP Network Programming Skills Summary", "PHP object-oriented Program Design Introduction Tutorial", "PHP string (String) Usage Summary", "php+ MySQL Database operations Introduction tutorial and PHP Common database operation Skills Summary
I hope this article will help you with the PHP program design.