How do I check if the request is made via AJAX in CodeIgniter?

If you are using a library that sends the X-Requested-With header, then you can do…

if (strtolower(filter_input(INPUT_SERVER, 'HTTP_X_REQUESTED_WITH')) === 'xmlhttprequest') {
   // I'm AJAX!
}

Leave a Comment