Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#5801 closed enhancement (fixed)

Let XMLHttp-requests send the X-Requested-With header

Reported by: guest Owned by: James Burke
Priority: high Milestone: 1.1
Component: IO Version: 1.0
Keywords: Cc:
Blocked By: Blocking:


jQuery, Prototype, YUI and - as it seems - Mootools send the header "X-Requested-With: XMLHttpRequest" with their XHRs. This is a quite convenient feature as it allows the server side to detect whether the current request is a partial request or not. Not only the client side is supported, also popular frameworks like Ruby on Rails, the Zend Framework and CakePHP support that header and expose functionality to the developer. I would really like to have Dojo send that header too.

Change History (8)

comment:1 Changed 14 years ago by alex

just pass the "headers" parameter. e.g.:

  url: "foo.php",
  content: { ... },
  headers: { "X-Requested-With": "XMLHttpRequest" }

Does that solve it for you? or are you looking for something like a djConfig flag?

comment:2 Changed 14 years ago by guest

I would vote for passing it per default as it is an acceptable behaviour a number of JS libraries share. If this is not possible, a config flag would do it for me.

comment:3 Changed 14 years ago by guest

Alex thanks for the header tip cause it will come handy (using dojo with rails so it will solve some problems... :) ). I belive it would be nice/good/cool/etc if dojo had this as default since all the other (or most of them) js libraries/frameworks do it. Just my two cents :)

comment:4 Changed 14 years ago by James Burke

Milestone: 1.1

Not sure if this is a good idea, since all our IO transports,, and dojo.xhr use common setup code. It does not seem right to send this for the non-xhr calls.

Instead of a djConfig flag, I suggest this call (works as of Dojo 1.1 -- that version defines the generic dojo.xhr() call that all xhr requests pass through):

dojo.connect(dojo, "xhr", function(args){
        args.headers = {};
    args.headers[""] = ["dojoXhr"];

comment:5 Changed 14 years ago by James Burke

Resolution: fixed
Status: newclosed

(In [12674]) Fixes #5801. Send X-Requested-With: XMLHttpRequest header with dojo.xhr calls, to match behavior of other libraries.

comment:6 Changed 14 years ago by James Burke

Ugh, ignore my comment above about it not being a good idea. I implemented it to keep parity with other toolkits.

comment:7 Changed 14 years ago by guest

Excellent! Thanks for implementing this jburke! :)

Do we know when this is going to be on a release package?

comment:8 Changed 14 years ago by James Burke

It will be part of the final 1.1 release. If we do any 1.1 betas (after beta2) or any release candidates, it will be in those builds too.

Note: See TracTickets for help on using tickets.