X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fajax.js;h=e4545335e895823e31fa9712e0857b061121c4d5;hb=b69dc841ff6d3a3a9bcb8ebe107f1d1cad8a634f;hp=441a7b9bf67b21d7838a2ac9250726b9be83c329;hpb=b8ceedbe2ba07f87a0f0e3862dfe012e8aa863b3;p=jquery.git diff --git a/src/ajax.js b/src/ajax.js index 441a7b9..e454533 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -12,8 +12,6 @@ jQuery.fn.extend({ url = url.slice(0, off); } - callback = callback || function(){}; - // Default to a GET request var type = "GET"; @@ -56,7 +54,8 @@ jQuery.fn.extend({ // If not, just inject the full result res.responseText ); - self.each( callback, [res.responseText, status, res] ); + if( callback ) + self.each( callback, [res.responseText, status, res] ); } }); return this; @@ -67,8 +66,7 @@ jQuery.fn.extend({ }, serializeArray: function() { return this.map(function(){ - return jQuery.nodeName(this, "form") ? - jQuery.makeArray(this.elements) : this; + return this.elements ? jQuery.makeArray(this.elements) : this; }) .filter(function(){ return this.name && !this.disabled && @@ -113,13 +111,6 @@ jQuery.extend({ dataType: type }); }, - - // Create the request object; Microsoft failed to properly - // implement the XMLHttpRequest in IE7, so we use the ActiveXObject when it is available - getAjaxTransport : function() { - return window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); - }, - getScript: function( url, callback ) { return jQuery.get(url, null, callback, "script"); @@ -159,6 +150,12 @@ jQuery.extend({ data: null, username: null, password: null, + // Create the request object; Microsoft failed to properly + // implement the XMLHttpRequest in IE7, so we use the ActiveXObject when it is available + // This function can be overriden by calling jQuery.ajaxSetup + xhr:function(){ + return window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); + }, accepts: { xml: "application/xml, text/xml", html: "text/html", @@ -282,7 +279,7 @@ jQuery.extend({ var requestDone = false; // Create the request object - var xhr = jQuery.getAjaxTransport(); + var xhr = s.xhr(); // Open the socket // Passing null username, generates a login popup on Opera (#2865) @@ -481,14 +478,18 @@ jQuery.extend({ if( s && s.dataFilter ) data = s.dataFilter( data, type ); - // If the type is "script", eval it in global context - if ( type == "script" ) - jQuery.globalEval( data ); + // The filter can actually parse the response + if( typeof data == 'string' ){ - // Get the JavaScript object, if JSON is used. - if ( type == "json" ) - data = eval("(" + data + ")"); + // If the type is "script", eval it in global context + if ( type == "script" ) + jQuery.globalEval( data ); + // Get the JavaScript object, if JSON is used. + if ( type == "json" ) + data = eval("(" + data + ")"); + } + return data; },