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');
   echo "ajax request";


Leave a Comment