Simplified XMLHttpRequest shadow (tested on 5.5, 6 and 7); Introduced preprocess callback (#384) - IE seems to fail to send the correct headers
This commit is contained in:
parent
94e59e287a
commit
a6ce303187
|
@ -134,10 +134,7 @@ jQuery.fn.extend({
|
||||||
// If IE is used, create a wrapper for the XMLHttpRequest object
|
// If IE is used, create a wrapper for the XMLHttpRequest object
|
||||||
if ( jQuery.browser.msie && typeof XMLHttpRequest == "undefined" )
|
if ( jQuery.browser.msie && typeof XMLHttpRequest == "undefined" )
|
||||||
XMLHttpRequest = function(){
|
XMLHttpRequest = function(){
|
||||||
return new ActiveXObject(
|
return new ActiveXObject("Microsoft.XMLHTTP");
|
||||||
navigator.userAgent.indexOf("MSIE 5") >= 0 ?
|
|
||||||
"Microsoft.XMLHTTP" : "Msxml2.XMLHTTP"
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Attach a bunch of functions for handling common AJAX events
|
// Attach a bunch of functions for handling common AJAX events
|
||||||
|
@ -487,6 +484,9 @@ jQuery.extend({
|
||||||
* (Boolean) async - By default, all requests are send asynchronous (set to true).
|
* (Boolean) async - By default, all requests are send asynchronous (set to true).
|
||||||
* If you need synchronous requests, set this option to false.
|
* If you need synchronous requests, set this option to false.
|
||||||
*
|
*
|
||||||
|
* (Function) preprocess - A pre-callback to set custom headers etc., the
|
||||||
|
* XMLHttpRequest is passed as the only argument.
|
||||||
|
*
|
||||||
* @example $.ajax({
|
* @example $.ajax({
|
||||||
* type: "GET",
|
* type: "GET",
|
||||||
* url: "test.js",
|
* url: "test.js",
|
||||||
|
@ -524,7 +524,8 @@ jQuery.extend({
|
||||||
data: null,
|
data: null,
|
||||||
contentType: "application/x-www-form-urlencoded",
|
contentType: "application/x-www-form-urlencoded",
|
||||||
processData: true,
|
processData: true,
|
||||||
async: true
|
async: true,
|
||||||
|
preprocess: null
|
||||||
}, s);
|
}, s);
|
||||||
|
|
||||||
// if data available
|
// if data available
|
||||||
|
@ -565,6 +566,10 @@ jQuery.extend({
|
||||||
// Make sure the browser sends the right content length
|
// Make sure the browser sends the right content length
|
||||||
if ( xml.overrideMimeType )
|
if ( xml.overrideMimeType )
|
||||||
xml.setRequestHeader("Connection", "close");
|
xml.setRequestHeader("Connection", "close");
|
||||||
|
|
||||||
|
// Allow custom headers/mimetypes
|
||||||
|
if( s.preprocess )
|
||||||
|
s.preprocess(xml);
|
||||||
|
|
||||||
// Wait for a response to come back
|
// Wait for a response to come back
|
||||||
var onreadystatechange = function(isTimeout){
|
var onreadystatechange = function(isTimeout){
|
||||||
|
|
|
@ -277,4 +277,21 @@ test("$.ajax - xml: non-namespace elements inside namespaced elements", function
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("$.ajax - preprocess", function() {
|
||||||
|
expect(1);
|
||||||
|
stop();
|
||||||
|
var customHeader = "value-for-custom-header";
|
||||||
|
$.ajax({
|
||||||
|
url: "data/name.php",
|
||||||
|
data: {'req': true},
|
||||||
|
preprocess: function(xml) {
|
||||||
|
xml.setRequestHeader('customHeader', customHeader)
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
ok( data == customHeader, "check return value, should be the custom header sent" );
|
||||||
|
start();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
Loading…
Reference in a new issue