Skip to main content
Home / Code Snippets / PHP / Detect AJAX Request

Detect AJAX Request

The HTTP_X_REQUESTED_WITH header is sent by all recent browsers that support AJAX requests.

if ( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' )
{
       # Ex. check the query and serve requested data
}
icon-link icon-logo-star icon-search icon-star