How to Detect AJAX Request using PHP

How to Detect AJAX Request using PHP

Detecting AJAX request is very useful, while your are working in AJAX based pagination. Last day worked in a project and I need to detect ajax or direct post request. Following script help me to detect AJAX request. Very simple but efficient script.

if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){  
    //If AJAX Request Then  
//something else  

Was this information useful? What other tips would you like to read about in the future? Share your comments, feedback and experiences with us by commenting below!

Back To Top