Sometimes, we need to check request is ajax or not in Codeigniter 3 application. If you want to call the same method but if the request is ajax then you perform differently, then you can do it by using $ this-> input object.

In Codeigniter 3 $ this-> input object provide is_ajax_request () method to check request is ajax or not, In the following example you can see how it works.

You can check to see the bellow controller method example so you can learn how to use is_ajax_request () and determine the request is from ajax or not.



* Get All Data from this method.
* @return Response
public function ajaxRequestPost()
    if ($this->input->is_ajax_request()) {
        $data = array(
            'title' => $this->input->post('title'),
            'description' => $this->input->post('description')
        $this->db->insert('items', $data);
        echo 'Added successfully.';  
        echo 'You can not access';

I hope this will help you .....