X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;ds=sidebyside;f=src%2Fajax.js;h=dbe731b294502665fde9f5c9188e6d6e39ea72d7;hb=5e50079b1472d9fef27fdc3f59c0f2e494556dd9;hp=3e43ffbdf317303d5339f73195b01b10c50538a2;hpb=042e51e731942ee48563e1caccd75d9ce226cf9d;p=jquery.git diff --git a/src/ajax.js b/src/ajax.js index 3e43ffb..dbe731b 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -26,7 +26,7 @@ jQuery.fn.extend({ params = null; // Otherwise, build a param string - } else { + } else if( typeof params == 'object' ) { params = jQuery.param( params ); type = "POST"; } @@ -336,7 +336,7 @@ jQuery.extend({ // Watch for, and catch, XML document parse errors try { // process the data (runs the xml through httpData regardless of callback) - data = jQuery.httpData( xhr, s.dataType, s.dataFilter ); + data = jQuery.httpData( xhr, s.dataType, s ); } catch(e) { status = "parsererror"; } @@ -460,7 +460,7 @@ jQuery.extend({ return false; }, - httpData: function( xhr, type, filter ) { + httpData: function( xhr, type, s ) { var ct = xhr.getResponseHeader("content-type"), xml = type == "xml" || !type && ct && ct.indexOf("xml") >= 0, data = xml ? xhr.responseXML : xhr.responseText; @@ -469,8 +469,8 @@ jQuery.extend({ throw "parsererror"; // Allow a pre-filtering function to sanitize the response - if( filter ) - data = filter( data, type ); + if( s.dataFilter ) + data = s.dataFilter( data, type ); // If the type is "script", eval it in global context if ( type == "script" ) @@ -486,14 +486,18 @@ jQuery.extend({ // Serialize an array of form elements or a set of // key/values into a query string param: function( a ) { - var s = []; + var s = [ ]; + + function add( key, value ){ + s[ s.length ] = encodeURIComponent(key) + '=' + encodeURIComponent(value); + }; // If an array was passed in, assume that it is an array // of form elements if ( a.constructor == Array || a.jquery ) // Serialize the form elements jQuery.each( a, function(){ - s.push( encodeURIComponent(this.name) + "=" + encodeURIComponent( this.value ) ); + add( this.name, this.value ); }); // Otherwise, assume that it's an object of key/value pairs @@ -503,10 +507,10 @@ jQuery.extend({ // If the value is an array then the key names need to be repeated if ( a[j] && a[j].constructor == Array ) jQuery.each( a[j], function(){ - s.push( encodeURIComponent(j) + "=" + encodeURIComponent( this ) ); + add( j, this ); }); else - s.push( encodeURIComponent(j) + "=" + encodeURIComponent( jQuery.isFunction(a[j]) ? a[j]() : a[j] ) ); + add( j, jQuery.isFunction(a[j]) ? a[j]() : a[j] ); // Return the resulting serialization return s.join("&").replace(/%20/g, "+");