How to use ci to detect ajax or page post to submit data? ciajax_PHP tutorial

Source: Internet
Author: User
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...

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.