X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fajax.js;h=7e024a319732d41f18cfa79b27d29ac10f67a2c7;hb=325755d4b38e87b13f9c24a4c2991ec497552aad;hp=42d0b280ca41478cc7f2f81acba382d69a2a50f4;hpb=335b8816c2f1e66de1fa245278794f8c7fdb1e01;p=jquery.git diff --git a/src/ajax.js b/src/ajax.js index 42d0b28..7e024a3 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 && @@ -78,7 +76,7 @@ jQuery.fn.extend({ .map(function(i, elem){ var val = jQuery(this).val(); return val == null ? null : - val.constructor == Array ? + jQuery.isArray(val) ? jQuery.map( val, function(val, i){ return {name: elem.name, value: val}; }) : @@ -97,6 +95,7 @@ jQuery.each( "ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".sp var jsc = now(); jQuery.extend({ + get: function( url, data, callback, type ) { // shift arguments if data argument was ommited if ( jQuery.isFunction( data ) ) { @@ -151,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", @@ -273,9 +278,8 @@ jQuery.extend({ var requestDone = false; - // Create the request object; Microsoft failed to properly - // implement the XMLHttpRequest in IE7, so we use the ActiveXObject when it is available - var xhr = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); + // Create the request object + var xhr = s.xhr(); // Open the socket // Passing null username, generates a login popup on Opera (#2865) @@ -470,17 +474,22 @@ jQuery.extend({ throw "parsererror"; // Allow a pre-filtering function to sanitize the response - if( s.dataFilter ) + // s != null is checked to keep backwards compatibility + 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; }, @@ -495,7 +504,7 @@ jQuery.extend({ // If an array was passed in, assume that it is an array // of form elements - if ( a.constructor == Array || a.jquery ) + if ( jQuery.isArray(a) || a.jquery ) // Serialize the form elements jQuery.each( a, function(){ add( this.name, this.value ); @@ -506,7 +515,7 @@ jQuery.extend({ // Serialize the key/values for ( var j in a ) // If the value is an array then the key names need to be repeated - if ( a[j] && a[j].constructor == Array ) + if ( jQuery.isArray(a[j]) ) jQuery.each( a[j], function(){ add( j, this ); });