CI detection is the method of Ajax or page post submission data, Ciajax
This article is an example of how CI detection is AJAX or page post submission data. Share to everyone for your reference. The implementation method is as follows:
First, the question:
Because the project requires that we want to know whether the submission data source is the data submitted by AJAX or the data submitted by the post of the page to be processed at different levels.
Second, the solution:
The workaround in PHP is as follows:
If it is an AJAX request, the value of the following expression is true
Copy the Code code as follows: $_server["Http_x_requested_with"]== "XMLHttpRequest"
is a PHP environment variable.
CI Processing methods:
Copy the Code code 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 in the use of thinkphp when there are built-in two constants Is_ajax and Is_post, want to use in CI for half a day as if not found, then automatic hands-on clothed
In the project's config/constants.php configuration file plus the top two lines of code, you can call it in all the methods directly
For example:
Copy the Code code as follows: if (Is_post) {
...
}
if (Is_ajax) {
...
}
It is hoped that this article will be helpful to the CI framework design of everyone.
http://www.bkjia.com/PHPjc/909350.html www.bkjia.com true http://www.bkjia.com/PHPjc/909350.html techarticle ci detection is the method of Ajax or page post submission data, Ciajax This example describes whether CI detection is AJAX or page post submission data method. Share to everyone for your reference. Concrete implementation ...