Page 1 of 1
XMLHttpRequest
Posted: Mon Dec 03, 2007 4:19 pm
by alex.barylski
How can I check if a request has been made via jQuery for an AJAX request...
The XMLHttpRequest is what is used on the client side and I assume that objects sets some special headers before submittion to server side script. If this is the case, then is there a way to parse the HTTP headers and determine if the request was made via XMLHttpRequest so I can handle that situation in my PHP code?
Posted: Mon Dec 03, 2007 4:25 pm
by arjan.top
i dont think thats possible, AJAX request is just standard POST/GET request
Posted: Mon Dec 03, 2007 4:32 pm
by alex.barylski
I found what I was looking for.

Posted: Mon Dec 03, 2007 5:25 pm
by volka
Mind to share?
Posted: Mon Dec 03, 2007 6:03 pm
by alex.barylski
volka wrote:Mind to share?
Look into Zend Http request...

Posted: Mon Dec 03, 2007 6:15 pm
by volka
Ok
Zend_Http_Request
Proxies the HTTP request environment, providing accessors for $_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, and PATH_INFO. Additionally, it contains methods accessors for the base URL and path.
And that helped you in exactly what way?
Posted: Mon Dec 03, 2007 7:53 pm
by John Cartwright
Hockey wrote:volka wrote:Mind to share?
Look into Zend Http request...

Code: Select all
$_SERVER ['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
?
Posted: Mon Dec 03, 2007 9:29 pm
by volka
Ah ok, and that works because e.g. Prototype sets this http header
prototype.js wrote:Code: Select all
setRequestHeaders: function() {
var headers = {
'X-Requested-With': 'XMLHttpRequest',
'X-Prototype-Version': Prototype.Version,
'Accept': 'text/javascript, text/html, application/xml, text/xml, */*'
};
Posted: Tue Dec 04, 2007 12:04 pm
by alex.barylski
Bingo! Just what I was looking for.
