Home  >  Article  >  Backend Development  >  Code example to detect ajax request in PHP_PHP tutorial

Code example to detect ajax request in PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:32:05790browse

In most cases, JavaScript-based Js frameworks such as jquery, Mootools, Prototype, etc., when issuing Ajax request instructions, will send additional HTTP_X_REQUESTED_WITH header information, as if it is an ajax request, so you can The server detects these Ajax requests. The detection method in PHP is as shown in the following code:

 1

 2if(!emptyempty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) =='xmlhttprequest'){

 3 //This is your ajax request processing logic

 4}else{

 5 //Some logic. . .

 6}

7?>

Used when developing Ajax interactive applications.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/756842.htmlTechArticleIn most cases, JavaScript-based Js frameworks such as jquery, Mootools, Prototype, etc., when issuing Ajax request instructions, Will send additional HTTP_X_REQUESTED_WITH header information, as if...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn