Codeigniter Check Request is Ajax or Not Example
Sometimes, we need to check request is ajax or not in codeigniter 3 application. If you want to call same method but if request is ajax then you perform different, then you can do by using $this->input object.
In Codeigniter 3 $this->input object provide is_ajax_request() method to check request is ajax or not, In following example you can see how it's works.
You can check see bellow controller method example so you can learn how to use is_ajax_request() and determine request is from ajax or not.
Example:
/**
* 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.';
}else{
echo 'You can not access';
}
}
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Codeigniter Create Zip File and Download Example
- Codeigniter Ajax Pagination using JQuery Example
- Codeigniter Delete Multiple Rows using Checkbox Example
- Codeigniter JQuery Ajax Request Example
- How to Create Dynamic Sitemap in Codeigniter?
- Codeigniter Multiple Database Connection Example
- How to Get and Set Config Variables in Codeigniter?
- Codeigniter Drag and Drop Multiple Image Upload Example
- How to Get Current Controller or Method Name in Codeigniter?
- How to Implement Flash Messages in Codeigniter?
- Codeigniter Ajax Infinite Scroll Pagination Example
- How to Get Last Inserted ID in Codeigniter?
- How to Get Current URL with Query String in Codeigniter?
- How to Get Current URL in Codeigniter?
- How to Get IP Address in Codeigniter?