Skip to content
Permalink
Browse files

Fixes a bug that prevented headers from being set in an ajaxSend call…

…back. Unit test modified.
  • Loading branch information
jaubourg committed Feb 7, 2011
1 parent 0c21c83 commit a2dbdc1f5438a857c2a9898bd36e4b2de685742e
Showing with 14 additions and 7 deletions.
  1. +2 −2 src/ajax.js
  2. +12 −5 test/unit/ajax.js
@@ -684,8 +684,7 @@ jQuery.extend({
if ( !transport ) {
done( -1, "No Transport" );
} else {
// Set state as sending
state = jqXHR.readyState = 1;
jqXHR.readyState = 1;
// Send global event
if ( fireGlobals ) {
globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
@@ -698,6 +697,7 @@ jQuery.extend({
}

try {
state = 1;
transport.send( requestHeaders, done );
} catch (e) {
// Propagate exception as error if not done
@@ -348,33 +348,40 @@ test(".ajax() - headers" , function() {

stop();

jQuery('#foo').ajaxSend(function( evt, xhr ) {
xhr.setRequestHeader( "ajax-send", "test" );
});

var requestHeaders = {
siMPle: "value",
"SometHing-elsE": "other value",
OthEr: "something else"
siMPle: "value",
"SometHing-elsE": "other value",
OthEr: "something else"
},
list = [],
i;

for( i in requestHeaders ) {
list.push( i );
}
list.push( "ajax-send" );

jQuery.ajax(url("data/headers.php?keys="+list.join( "_" ) ), {

headers: requestHeaders,
success: function( data , _ , xhr ) {
var tmp = [];
for ( i in requestHeaders ) {
tmp.push( i , ": " , requestHeaders[ i ] , "\n" );
}
tmp.push( "ajax-send: test\n" );
tmp = tmp.join( "" );

equals( data , tmp , "Headers were sent" );
equals( xhr.getResponseHeader( "Sample-Header" ) , "Hello World" , "Sample header received" );
start();
},
error: function(){ ok(false, "error"); }
});

}).then( start, start );

});

0 comments on commit a2dbdc1

Please sign in to comment.
You can’t perform that action at this time.