Ticket #384 (closed bug: worksforme)
IE fails to send/set custom request headers
| Reported by: | choan.galvez@… | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | 1.1.4 |
| Component: | ajax | Version: | 1.1.3 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description (last modified by john) (diff)
It'd be nice to allow custom request headers in AJAX requests.
Here is a patch:
Index: src/ajax/ajax.js
===================================================================
--- src/ajax/ajax.js (revision 569)
+++ src/ajax/ajax.js (working copy)
@@ -710,6 +710,7 @@
dataType: null,
data: null,
url: null,
+ headers: {}
}, s);
// if data available
@@ -746,6 +747,10 @@
// Set header so the called script knows that it's an XMLHttpRequest
xml.setRequestHeader("X-Requested-With", "XMLHttpRequest");
+
+ jQuery.each(s.headers, function(i) {
+ xml.setRequestHeader(i, this);
+ });
// Make sure the browser sends the right content length
if ( xml.overrideMimeType )
Change History
comment:1 Changed 7 years ago by Luis
- Component ajax deleted
- Summary changed from Allow custom request headers in AJAX requests to Allow
- Priority minor deleted
- Owner john deleted
- Keywords ajax, headers removed
- Type feature deleted
comment:2 Changed 7 years ago by aaron.heimli
- Component set to ajax
- Summary changed from Allow to Allow custom request headers
- Priority set to major
- Owner set to john
- Keywords ajax, headers added
- Type set to enhancement
comment:4 Changed 7 years ago by jonsons
- Component ajax deleted
- Summary changed from Allow custom request headers to Allow
- Priority major deleted
- Owner john deleted
- Version 1.1 deleted
- Milestone 1.1 deleted
- Keywords ajax, headers removed
- Type enhancement deleted
Nice gusetbook! |
comment:9 Changed 6 years ago by Kelvin Luck
I'd like to vote for the inclusion of this into jQuery ASAP.
comment:10 Changed 6 years ago by joern
- Component set to ajax
- Summary changed from Allow to IE fails to send/set custom request headers
- Priority set to major
- Owner set to john
- Version set to 1.1
- Milestone set to 1.1
- Keywords request, removed
- Type set to bug
There is now a "preprocess" option for $.ajax that allows to set both custom headers and override mimeTypes. IE (5 - 7) seems to fail to set/send custom headers, therefore I leave this ticket open until a solution or explanation is found for that issue.
comment:11 Changed 6 years ago by joern
Renamed "preprocess" to "before" for consistency with form plugin.
comment:12 Changed 6 years ago by joern
The callback is now "beforeSend".
The tests still fail for IE. Using a pseudo-standard header starting with "X-..." doesn't help either.
comment:13 Changed 6 years ago by joern
- Status changed from new to closed
- Resolution set to fixed
Seems like this is only a problem in the testsuite, as noone else is reporting this problem.
comment:14 Changed 6 years ago by spinal007
- Status changed from closed to reopened
- Resolution fixed deleted
I'm currently having the same problem in FF. the 'X-Requested-With' header which should be built-in to jQuery is not being sent with the 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...
comment:15 Changed 6 years ago by john
- Status changed from reopened to closed
- Description modified (diff)
- Version changed from 1.1a to 1.1.3
- Milestone changed from 1.1a to 1.1.4
- need set to Review
- Resolution set to worksforme
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

iam we! |