Test for AJAX Header in PHP


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /* decide what the content should be up here .... */
  2. $content = get_content(); //generic function;
  3.  
  4. /* AJAX check */
  5. if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
  6. /* special ajax here */
  7. die($content);
  8. }
  9.  
  10. /* not ajax, do more.... */

URL: http://davidwalsh.name/detect-ajax

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.