Using PHP you can easily know if your request was using AJAX or not. I found this interesting article published on ElectricToolbox that explains how to determine if a Request is using AJAX or not in PHP. By using it you can easily branch your code for AJAX based calls and normal calls. For example, it may be useful when you need to generate different response depending on the request type.
Basically what they explain is that you can a simple define that is set to TRUE if HTTP_X_REQUESTED_WITH variable is set to “xmlhttprequest” as a server variable.
define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
Then you can easily use an IF condition to determine if the call is AJAX ir not, by using the IS_AJAX definition.
if(IS_AJAX) {
// it is an AJAX Call
}
else {
// it is not an AJAX Call
}
And that’s all.
