Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Way to tell if a post came from an ajax call in codeigniter?

Tags:

I just started using CodeIgniter after using Zend for a while. My new site has a feature where you register through Ajax. In Zend I could use this to check if the incoming POST was through AJAX, and therefore from my site:

if(!$this->getRequest()->isXMLHttpRequest())

Is there a piece of code in CodeIgniter that does the same thing? If I don't make sure it's an AJAX call, someone could theoretically register anything they wanted by creating a form to post to my controller.

Thanks!

like image 747
Ethan Avatar asked Nov 22 '09 18:11

Ethan


People also ask

How does CodeIgniter receive the Ajax post data in controller?

php in view folder and ajax_post_controller. php in controller folder. In this example first the controller will load the view page. After data submission jQuery Ajax post function send data to controller's function and after performing some task it will return data to view page without refreshing.


1 Answers

Since CodeIgniter 2.0, there is an easier way of checking for an ajax request.

Use: $this->input->is_ajax_request();

Doc: https://codeigniter.com/user_guide/libraries/input.html

like image 112
CopyJosh Avatar answered Sep 19 '22 07:09

CopyJosh