From a2dbdc1f5438a857c2a9898bd36e4b2de685742e Mon Sep 17 00:00:00 2001 From: jaubourg Date: Mon, 7 Feb 2011 16:35:32 +0100 Subject: [PATCH] Fixes a bug that prevented headers from being set in an ajaxSend callback. Unit test modified. --- src/ajax.js | 4 ++-- test/unit/ajax.js | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/ajax.js b/src/ajax.js index 4830e3df8..2b6b80f90 100644 --- a/src/ajax.js +++ b/src/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 diff --git a/test/unit/ajax.js b/test/unit/ajax.js index cf7c0ad0b..59159c320 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -348,10 +348,14 @@ 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; @@ -359,22 +363,25 @@ test(".ajax() - headers" , function() { 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 ); }); -- 2.39.5