I need to deal with these two cases differently,is there a good solution?
views:
52answers:
2
+4
A:
if ($_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest') { /* ajax request */ }
Sergei
2010-02-12 06:58:26
Dunno how reliable that is though...
Mark
2010-02-12 07:01:08
it's reliable and pretty standard.
Sergei
2010-02-12 07:05:42
+3
A:
I can think of 2 ways to accomplish this:
On the AJAX side you could set a custom HTTP header with
XMLHttpRequest.setRequestHeader()
and then check for the presence of that header on the PHP side withgetallheaders()
to indicate that the request was made by an AJAX client. If your php script doesn't find the custom header, you can consider it to be a non-AJAX request.When you create the request in your code, you could simply tack on a querystring variable to indicate the nature of the request. eg. http://example.com/process?ajax=true for an AJAX reqeust or http://example.com/process?ajax=false for a non-AJAX request.
Asaph
2010-02-12 06:58:33