Ciajax is the method for detecting whether to use ajax or page post to submit data. Ci checks whether ajax or page post submits data. ciajax examples in this article describe how ci checks ajax or page post submits data. Share it with you for your reference. The specific method for implementing the ci detection is ajax or page post data submission, 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.
The code is as follows:
$ _ SERVER ["HTTP_X_REQUESTED_WITH"] = "XMLHttpRequest"
Is an environment variable of PHP.
Ci solution:
The 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:
The code is as follows:
If (IS_POST ){
...
}
If (IS_AJAX ){
...
}
I hope this article will help you with CI framework programming.
Examples in this article describes how to use ci to detect ajax or page post to submit data. Share it with you for your reference. Specific implementation...