aboutsummaryrefslogtreecommitdiffstats
path: root/src/ajax
diff options
context:
space:
mode:
authorJörn Zaefferer <joern.zaefferer@gmail.com>2006-12-04 19:37:49 +0000
committerJörn Zaefferer <joern.zaefferer@gmail.com>2006-12-04 19:37:49 +0000
commita6ce3031871aca7c067672e91d298dd2a5bf176c (patch)
treec7eea3b65e6da46cb6bdceed2426f81ed13bc51b /src/ajax
parent94e59e287a9fde9425cd96713e8130aef06bc431 (diff)
downloadjquery-a6ce3031871aca7c067672e91d298dd2a5bf176c.tar.gz
jquery-a6ce3031871aca7c067672e91d298dd2a5bf176c.zip
Simplified XMLHttpRequest shadow (tested on 5.5, 6 and 7); Introduced preprocess callback (#384) - IE seems to fail to send the correct headers
Diffstat (limited to 'src/ajax')
-rw-r--r--src/ajax/ajax.js15
-rw-r--r--src/ajax/ajaxTest.js17
2 files changed, 27 insertions, 5 deletions
diff --git a/src/ajax/ajax.js b/src/ajax/ajax.js
index d56ae0f1e..fe83993a7 100644
--- a/src/ajax/ajax.js
+++ b/src/ajax/ajax.js
@@ -134,10 +134,7 @@ jQuery.fn.extend({
// 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
@@ -487,6 +484,9 @@ jQuery.extend({
* (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",
@@ -524,7 +524,8 @@ jQuery.extend({
data: null,
contentType: "application/x-www-form-urlencoded",
processData: true,
- async: true
+ async: true,
+ preprocess: null
}, s);
// if data available
@@ -565,6 +566,10 @@ jQuery.extend({
// 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){
diff --git a/src/ajax/ajaxTest.js b/src/ajax/ajaxTest.js
index 98f7cfcdd..a84df1d6c 100644
--- a/src/ajax/ajaxTest.js
+++ b/src/ajax/ajaxTest.js
@@ -277,4 +277,21 @@ test("$.ajax - xml: non-namespace elements inside namespaced elements", function
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