Home >Backend Development >PHP Tutorial >How to detect if ci is submitting data via ajax or page post, ciajax_PHP tutorial
The example in this article describes the method of ci detecting whether the data is submitted by ajax or page post. Share it with everyone for your reference. The specific implementation method is as follows:
1. Question:
Because of the project needs, we want to know whether the source of the submitted data is the data submitted by ajax or the data submitted by the post of the page, so that we can process it at different levels.
2. Solution:
The solution in php is as follows:
If it is an ajax request, the value of the following expression is true
How to handle it in ci:
I remember that when using THINKPHP, there are two built-in constants IS_AJAX and IS_POST. I want to use it in ci and I have searched for a long time but can’t find it. Then I can do it automatically
Add the above two lines of code to the project's config/constants.php configuration file. Now you can call it directly in all methods
For example:
I hope this article will be helpful to everyone’s CI framework programming.