Bug Tracker

Opened 14 years ago

Closed 13 years ago

Last modified 8 years ago

#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:
Blocked by: Blocking:

Description (last modified by john)

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 (15)

comment:1 Changed 14 years ago by Luis

Component: ajax
Keywords: added; ajax headers removed
Owner: john deleted
Priority: minor
Summary: Allow custom request headers in AJAX requestsAllow
Type: feature

iam we! |

comment:2 Changed 14 years ago by aaron.heimli

Component: ajax
Keywords: ajax headers added; removed
Owner: set to john
Priority: major
Summary: AllowAllow custom request headers
Type: enhancement

comment:3 Changed 14 years ago by joern

Milestone: 1.1
Version: 1.1

comment:4 Changed 14 years ago by jonsons

Component: ajax
Keywords: added; ajax headers removed
Milestone: 1.1
Owner: john deleted
Priority: major
Summary: Allow custom request headersAllow
Type: enhancement
Version: 1.1

Nice gusetbook! |

comment:5 Changed 14 years ago by jonsonz

Nice gusetbook! |

comment:6 Changed 14 years ago by kikloin

Nice gusetbook! |

comment:7 Changed 14 years ago by kikloin

Nice gusetbook! |

comment:8 Changed 14 years ago by klikital

Nklikital Nice |

comment:9 Changed 13 years ago by Kelvin Luck

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

comment:10 Changed 13 years ago by joern

Component: ajax
Keywords: request removed
Milestone: 1.1
Owner: set to 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.

comment:11 Changed 13 years ago by joern

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

comment:12 Changed 13 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 13 years ago by joern

Resolution: fixed
Status: newclosed

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

comment:14 Changed 13 years ago by spinal007

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

comment:15 Changed 13 years ago by john

Description: modified (diff)
Milestone: 1.1a1.1.4
need: Review
Resolution: worksforme
Status: reopenedclosed
Version: 1.1a1.1.3
Note: See TracTickets for help on using tickets.