Skip to main content

Bug Tracker

Side navigation

#384 closed bug (worksforme)

Opened November 12, 2006 06:26PM UTC

Closed August 19, 2007 09:06PM UTC

Last modified March 14, 2012 10:50PM UTC

IE fails to send/set custom request headers

Reported by: choan.galvez@gmail.c Owned by:
Priority: major Milestone: 1.1.4
Component: ajax Version: 1.1.3
Keywords: Cc:
Blocked by: Blocking:
Description

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 )

Attachments (0)
Change History (15)

Changed November 12, 2006 11:43PM UTC by Luis comment:1

component: ajax
keywords: request, ajax, headersrequest,
owner: john
priority: minor
summary: Allow custom request headers in AJAX requestsAllow
type: feature

iam we! |

Changed November 13, 2006 01:35AM UTC by aaron.heimli comment:2

component: → ajax
keywords: request,request, ajax, headers
owner: → john
priority: → major
summary: AllowAllow custom request headers
type: → enhancement

Changed November 13, 2006 08:45AM UTC by joern comment:3

milestone: → 1.1
version: → 1.1

Changed November 15, 2006 05:34AM UTC by jonsons comment:4

component: ajax
keywords: request, ajax, headersrequest,
milestone: 1.1
owner: john
priority: major
summary: Allow custom request headersAllow
type: enhancement
version: 1.1

Nice gusetbook! |

Changed November 17, 2006 03:10AM UTC by jonsonz comment:5

Nice gusetbook! |

Changed November 19, 2006 01:35AM UTC by kikloin comment:6

Nice gusetbook! |

Changed November 21, 2006 08:05AM UTC by kikloin comment:7

Nice gusetbook! |

Changed November 24, 2006 02:51AM UTC by klikital comment:8

Nklikital Nice |

Changed December 04, 2006 05:05PM UTC by Kelvin Luck comment:9

I'd like to vote for the inclusion of this into jQuery ASAP.

Changed December 04, 2006 07:39PM UTC by joern comment:10

component: → ajax
keywords: request,
milestone: → 1.1
owner: → john
priority: → major
summary: AllowIE fails to send/set custom request headers
type: → bug
version: → 1.1

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.

Changed December 04, 2006 07:41PM UTC by joern comment:11

Renamed "preprocess" to "before" for consistency with form plugin.

Changed December 11, 2006 09:12AM UTC by joern comment:12

The callback is now "beforeSend".

The tests still fail for IE. Using a pseudo-standard header starting with "X-..." doesn't help either.

Changed December 21, 2006 03:24PM UTC by joern comment:13

resolution: → fixed
status: newclosed

Seems like this is only a problem in the testsuite, as noone else is reporting this problem.

Changed March 27, 2007 09:42PM UTC by spinal007 comment:14

resolution: fixed
status: closedreopened

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...

Changed August 19, 2007 09:06PM UTC by john comment:15

description: 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 )\ \ }}}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 ) \ \ }}}
milestone: 1.1a1.1.4
need: → Review
resolution: → worksforme
status: reopenedclosed
version: 1.1a1.1.3