Is there anyway to check whether an incoming request is of AJAX JSON type?
I tried
if(($_SERVER['REQUEST_METHOD']=='JSON'))
{
}
But it didn't work.
Any thoughts?
You would need to set a header from the client side. jQuery and other libraries set a x-requested-with
header:
if(strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
{
echo "Ajax request";
}
You can do a check on the accept param, if it's text/javascript your talking json, if it's text/xml guess what :P
$_SERVER['HTTP_ACCEPT']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With