Skip to content

Instantly share code, notes, and snippets.

@eugene-ilyin
Last active January 28, 2016 16:59
Show Gist options
  • Save eugene-ilyin/53df17cb711dd757023c to your computer and use it in GitHub Desktop.
Save eugene-ilyin/53df17cb711dd757023c to your computer and use it in GitHub Desktop.
Check that request is AJAX
/**
* Check if current request is AJAX.
*/
function MODULE_NAME_is_ajax() {
$http_request = isset($_SERVER['HTTP_X_REQUESTED_WITH'])
&& strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
// Check ajax in IE.
$request_uri = isset($_SERVER['REQUEST_URI'])
&& strtolower($_SERVER['REQUEST_URI']) == '/system/ajax';
return $http_request || $request_uri || !empty($_GET['ajax']);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment