XMLHttpRequest

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

XMLHttpRequest

Post 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?
User avatar
arjan.top
Forum Contributor
Posts: 305
Joined: Sun Oct 14, 2007 4:36 am
Location: Hoče, Slovenia

Post by arjan.top »

i dont think thats possible, AJAX request is just standard POST/GET request
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

I found what I was looking for. :)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Mind to share?
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

volka wrote:Mind to share?
Look into Zend Http request... :)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Hockey wrote:
volka wrote:Mind to share?
Look into Zend Http request... :)

Code: Select all

$_SERVER ['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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, */*'
    };
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

Bingo! Just what I was looking for. :)
Post Reply