Ci checks whether ajax or page post submits data. ciajax
This article describes how to use ci to detect ajax or page post to submit data. Share it with you for your reference. The specific implementation method is as follows:
I. Problems:
Because the project requires us to know whether the source of the submitted data is the data submitted by ajax or the data submitted by the page post for different levels of processing.
Ii. solution:
The solution in php is as follows:
For an ajax request, the value of the following expression is true.
Copy codeThe Code is as follows: $ _ SERVER ["HTTP_X_REQUESTED_WITH"] = "XMLHttpRequest"
Is an environment variable of PHP.
Ci solution:
Copy codeThe Code IS as follows: 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 and IS_POST. If you want to use them in ci for a long time, it seems that they have not been found, then you will be able to help yourself.
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:
Copy codeThe Code is as follows: if (IS_POST ){
...
}
If (IS_AJAX ){
...
}
I hope this article will help you with CI framework programming.