Posted By

Wilco on 08/03/09


Tagged

ajax javascript php XMLHttpRequest


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

vali29
cro1979
VaiT
umang_nine


Check for AJAX Request


 / Published in: PHP
 

Determines whether or not the page has been requested directly, or through AJAX. This can allow for combining a page and related AJAX responses within the same script.

  1. function isAjaxRequest() {
  2. return (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
  3. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Wilco on August 3, 2009

Forgot to mention this snippet was inspired by David Walsh's post here: http://davidwalsh.name/detect-ajax

Posted By: Wilco on August 3, 2009

Forgot to mention this snippet was inspired by David Walsh's post here: http://davidwalsh.name/detect-ajax

You need to login to post a comment.