How to Use ci to detect ajax or page post to submit data _ php instance

Source: Internet
Author: User
This article mainly introduces how to use ci to detect ajax or page post to submit data. The PHP environment variables are used as the basic instance to demonstrate how to modify the CI framework configuration file, it is very practical. If you need it, you can refer to the examples in this article to describe 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.

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.