// If IE is used, create a wrapper for the XMLHttpRequest object
if ( jQuery.browser.msie && typeof XMLHttpRequest == "undefined" )
XMLHttpRequest = function(){
- return new ActiveXObject(
- navigator.userAgent.indexOf("MSIE 5") >= 0 ?
- "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP"
- );
+ return new ActiveXObject("Microsoft.XMLHTTP");
};
// Attach a bunch of functions for handling common AJAX events
* (Boolean) async - By default, all requests are send asynchronous (set to true).
* 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({
* type: "GET",
* url: "test.js",
data: null,
contentType: "application/x-www-form-urlencoded",
processData: true,
- async: true
+ async: true,
+ preprocess: null
}, s);
// if data available
// Make sure the browser sends the right content length
if ( xml.overrideMimeType )
xml.setRequestHeader("Connection", "close");
+
+ // Allow custom headers/mimetypes
+ if( s.preprocess )
+ s.preprocess(xml);
// Wait for a response to come back
var onreadystatechange = function(isTimeout){
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();
+ }
+ });
});
\ No newline at end of file