Skip to content

Commit 9181048

Browse files
committed
beforeSend invoked after xhrFields are processed
1 parent d5241b0 commit 9181048

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

can-ajax-test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ QUnit.test("It doesn't stringify FormData", function(assert) {
569569
});
570570
});
571571

572-
QUnit.test("beforsend", function (assert) {
572+
QUnit.test("beforeSend", function (assert) {
573573
var done = assert.async();
574574
var headers = {},
575575
restore = makeFixture(function () {
@@ -594,11 +594,15 @@ QUnit.test("beforsend", function (assert) {
594594
id: "qux"
595595
},
596596
dataType: "json",
597+
xhrFields: {
598+
'CustomHeader': 'CustomValue'
599+
},
597600
beforeSend: function (xhr){
601+
assert.ok(xhr.hasOwnProperty('CustomHeader'), "xhrField header set");
598602
xhr.setRequestHeader("Authorization", "Bearer 123");
599603
}
600604
}).then(function (value) {
601-
assert.ok(headers.hasOwnProperty('Authorization'), "custom header set");
605+
assert.ok(headers.hasOwnProperty('Authorization'), "authorization header set");
602606
}, function (reason) {
603607
assert.notOk(reason, "request failed with reason = ", reason);
604608
}).then(function () {

can-ajax.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,16 @@ function ajax(o) {
244244
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
245245
}
246246

247-
if(o.beforeSend){
248-
o.beforeSend.call( o, xhr, o );
249-
}
250-
251247
if (o.xhrFields) {
252248
for (var f in o.xhrFields) {
253249
xhr[f] = o.xhrFields[f];
254250
}
255251
}
256252

253+
if(o.beforeSend){
254+
o.beforeSend.call( o, xhr, o );
255+
}
256+
257257
xhr.send(data);
258258
return promise;
259259
}

0 commit comments

Comments
 (0)