CI detection is the method of Ajax or page post submission data, ciajax_php tutorial

Source: Internet
Author: User

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 ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.