Check for Ajax request in CodeIgniter

Check for Ajax request in CodeIgniter::

To check Ajax Request in CodeIgniter, we will use CodeIgniter Output Class Method class is_ajax_request() , this function checks if the HTTP_X_REQUESTED_WITH server header has been set, if set response will be true otherwise false means it will returns a boolean response

You can use $this->input->is_ajax_request() from the input class.

if (!$this->input->is_ajax_request()) {
   exit('No direct script access allowed');
}else{
   echo "ajax request";
}

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

Please follow and like us:
0

Leave a Reply

Your email address will not be published. Required fields are marked *