Side navigation
#1079 closed bug (worksforme)
Opened March 27, 2007 09:46PM UTC
Closed August 19, 2007 09:06PM UTC
FF and IE fail to send custom headers
Reported by: | spinal007 | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.1.4 |
Component: | ajax | Version: | 1.1.3 |
Keywords: | ajax custom header headers XMLHttpRequest X-Requested-With | Cc: | |
Blocked by: | Blocking: |
Description
The 'X-Requested-With' header which should be built-in to jQuery is not being sent with the ajax request. I've checked every line of the code and I'm certain the following lines get executed:
1998 Set header so the called script knows that it's an XMLHttpRequest
1999 xml.setRequestHeader("X-Requested-With", "XMLHttpRequest");
I've also tried my own implementation... Add custom header to every call (HTTP_X_METHOD:Ajax)
$().ajaxSend(function(a,r,o){ r.setRequestHeader("X-Method", "Ajax"); });
But this also fails...
Attachments (1)
Change History (5)
Changed March 28, 2007 01:43AM UTC by comment:1
Changed March 28, 2007 02:24AM UTC by comment:2
It seems to work when I use ajaxSetup to set global to true.
However,
1. the documentation says this option should be true by default
2. xml.setRequestHeader("X-Requested-With", "XMLHttpRequest"); executes even if global is false, so the X-Requested-With header should have been sent.
3. I custom headers set via ajaxSend should still have worked.
This is the patch I'm using...
(Note: I use the custom header 'X-Method', but this can be used for any other custom headers)
// Ajax default settings $.ajaxSetup({ global:true, type:'GET', headers: {"X-Method":"Ajax"}, beforeSend:function(r,o){ }, data:{} }); // Add custom headers before every call (HTTP_X_METHOD:Ajax) $().ajaxSend(function(a,r,o){ jQuery.each( (o.headers || {}), function(i){ r.setRequestHeader(i, this); } ); });
Changed April 05, 2007 02:43PM UTC by comment:3
Do you have a sample page which demonstrates this? If you look at the jQuery source code you will see that the X-Requested-With request header is *always* set. How are you confirming its absence?
Changed April 18, 2007 04:12PM UTC by comment:4
I confirmed its absence using a simple by calling a simple ASP script via Ajax that prints all headers sent to the server.
Since reporting this behaviour I have downloaded the latest release of jQuery and I can no longer re-create it, which leads me to the assumption that a) it's been fixed, or b) it was an error with my code and I've since fixed it.
Either way, everything is fine now...
Changed August 19, 2007 09:06PM UTC by comment:5
description: | The 'X-Requested-With' header which should be built-in to jQuery is not being sent with the ajax request. I've checked every line of the code and I'm certain the following lines get executed:\ \ 1998 // Set header so the called script knows that it's an XMLHttpRequest\ 1999 xml.setRequestHeader("X-Requested-With", "XMLHttpRequest");\ \ I've also tried my own implementation... // Add custom header to every call (HTTP_X_METHOD:Ajax) \ $().ajaxSend(function(a,r,o){ r.setRequestHeader("X-Method", "Ajax"); });\ \ But this also fails... → The 'X-Requested-With' header which should be built-in to jQuery is not being sent with the ajax request. I've checked every line of the code and I'm certain the following lines get executed: \ \ 1998 // Set header so the called script knows that it's an XMLHttpRequest \ 1999 xml.setRequestHeader("X-Requested-With", "XMLHttpRequest"); \ \ I've also tried my own implementation... // Add custom header to every call (HTTP_X_METHOD:Ajax) \ $().ajaxSend(function(a,r,o){ r.setRequestHeader("X-Method", "Ajax"); }); \ \ But this also fails... |
---|---|
milestone: | 1.1.3 → 1.1.4 |
resolution: | → worksforme |
status: | new → closed |
version: | 1.1.1 → 1.1.3 |
I've now tried the following:
I've verified that the code within function customHeaders does execute during runtime. No errors are reported but the headers are not included in the request.