In php
For an ajax request, the value of the following expression is true.
The code is as follows: |
Copy code |
$ _ SERVER ["HTTP_X_REQUESTED_WITH"] = "XMLHttpRequest"
|
Is an environment variable of PHP.
Ci solution
The code is as follows: |
Copy code |
Define ('is _ AJAX ', isset ($ _ SERVER ['http _ X_REQUESTED_WITH']) & strtolower ($ _ SERVER ['http _ X_REQUESTED_WITH ']) = 'xmlhttprequest '); Define ("IS_POST", strtolower ($ _ SERVER ['request _ method']) = 'post '); |
Remember that when THINKPHP is used, there are two built-in constants, IS_AJAX IS_POST. If I want to use THINKPHP for a long time, it seems that I haven't found it, then I will be able to help myself
Add the above two lines of code to the config/constants. php configuration file of the project, and then you can directly call
For example:
The code is as follows: |
Copy code |
If (IS_POST ){ ... } If (IS_AJAX ){ ... } |