Skip to content

Instantly share code, notes, and snippets.

@shalaby
Created March 7, 2014 19:49
Show Gist options
  • Save shalaby/9418559 to your computer and use it in GitHub Desktop.
Save shalaby/9418559 to your computer and use it in GitHub Desktop.
Detect ajax request in php
/* decide what the content should be up here .... */
$content = get_content(); //generic function;
/* AJAX check */
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
/* special ajax here */
die($content);
}
/* not ajax, do more.... */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment