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

Code example to detect ajax request in PHP_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:32:05
Original
883 people have browsed it

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 of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template