Fixes a bug that prevented headers from being set in an ajaxSend callback. Unit test modified.
This commit is contained in:
parent
0c21c83e96
commit
a2dbdc1f54
|
@ -684,8 +684,7 @@ jQuery.extend({
|
||||||
if ( !transport ) {
|
if ( !transport ) {
|
||||||
done( -1, "No Transport" );
|
done( -1, "No Transport" );
|
||||||
} else {
|
} else {
|
||||||
// Set state as sending
|
jqXHR.readyState = 1;
|
||||||
state = jqXHR.readyState = 1;
|
|
||||||
// Send global event
|
// Send global event
|
||||||
if ( fireGlobals ) {
|
if ( fireGlobals ) {
|
||||||
globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
|
globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
|
||||||
|
@ -698,6 +697,7 @@ jQuery.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
state = 1;
|
||||||
transport.send( requestHeaders, done );
|
transport.send( requestHeaders, done );
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Propagate exception as error if not done
|
// Propagate exception as error if not done
|
||||||
|
|
|
@ -348,6 +348,10 @@ test(".ajax() - headers" , function() {
|
||||||
|
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
|
jQuery('#foo').ajaxSend(function( evt, xhr ) {
|
||||||
|
xhr.setRequestHeader( "ajax-send", "test" );
|
||||||
|
});
|
||||||
|
|
||||||
var requestHeaders = {
|
var requestHeaders = {
|
||||||
siMPle: "value",
|
siMPle: "value",
|
||||||
"SometHing-elsE": "other value",
|
"SometHing-elsE": "other value",
|
||||||
|
@ -359,22 +363,25 @@ test(".ajax() - headers" , function() {
|
||||||
for( i in requestHeaders ) {
|
for( i in requestHeaders ) {
|
||||||
list.push( i );
|
list.push( i );
|
||||||
}
|
}
|
||||||
|
list.push( "ajax-send" );
|
||||||
|
|
||||||
jQuery.ajax(url("data/headers.php?keys="+list.join( "_" ) ), {
|
jQuery.ajax(url("data/headers.php?keys="+list.join( "_" ) ), {
|
||||||
|
|
||||||
headers: requestHeaders,
|
headers: requestHeaders,
|
||||||
success: function( data , _ , xhr ) {
|
success: function( data , _ , xhr ) {
|
||||||
var tmp = [];
|
var tmp = [];
|
||||||
for ( i in requestHeaders ) {
|
for ( i in requestHeaders ) {
|
||||||
tmp.push( i , ": " , requestHeaders[ i ] , "\n" );
|
tmp.push( i , ": " , requestHeaders[ i ] , "\n" );
|
||||||
}
|
}
|
||||||
|
tmp.push( "ajax-send: test\n" );
|
||||||
tmp = tmp.join( "" );
|
tmp = tmp.join( "" );
|
||||||
|
|
||||||
equals( data , tmp , "Headers were sent" );
|
equals( data , tmp , "Headers were sent" );
|
||||||
equals( xhr.getResponseHeader( "Sample-Header" ) , "Hello World" , "Sample header received" );
|
equals( xhr.getResponseHeader( "Sample-Header" ) , "Hello World" , "Sample header received" );
|
||||||
start();
|
|
||||||
},
|
},
|
||||||
error: function(){ ok(false, "error"); }
|
error: function(){ ok(false, "error"); }
|
||||||
});
|
|
||||||
|
}).then( start, start );
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue