X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fajax.js;h=c3927d15412fd600b5595c85aaceb6d8a8104839;hb=96dd06ea50674c77de4a5d953c227bb54d9276af;hp=adae6aec7493b52bcd35a40b78d129affdfce38c;hpb=fe80b5af45049d1c8d10682eb1075f838d52a045;p=jquery.git diff --git a/src/ajax.js b/src/ajax.js index adae6ae..c3927d1 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -370,7 +370,7 @@ jQuery.extend({ // Wait for a response to come back var onreadystatechange = function(isTimeout){ // The request was aborted, clear the interval and decrement jQuery.active - if ( xhr.readyState === 0 ) { + if ( !xhr || xhr.readyState === 0 ) { if ( ival ) { // clear poll interval clearInterval( ival ); @@ -451,7 +451,7 @@ jQuery.extend({ // Send the data try { - xhr.send( type === "POST" ? s.data : null ); + xhr.send( type === "POST" || type === "PUT" ? s.data : null ); } catch(e) { jQuery.handleError(s, xhr, null, e); } @@ -588,23 +588,28 @@ jQuery.extend({ // of form elements if ( jQuery.isArray(a) || a.jquery ) { // Serialize the form elements - jQuery.each( a, function(){ + jQuery.each( a, function() { add( this.name, this.value ); }); - - // Otherwise, assume that it's an object of key/value pairs } else { - // Serialize the key/values - for ( var j in a ) { - // If the value is an array then the key names need to be repeated - if ( jQuery.isArray(a[j]) ) { - jQuery.each( a[j], function(){ - add( j, this ); - }); + // Recursively encode parameters from object, + // building a prefix path as we go down + function buildParams(obj, prefix) + { + if ( jQuery.isArray(obj) ) { + for ( var i = 0, length = obj.length; i < length; i++ ) { + buildParams( obj[i], prefix ); + }; + } else if( typeof(obj) == "object" ) { + for ( var j in obj ) { + var postfix = ((j.indexOf("[]") > 0) ? "[]" : ""); // move any brackets to the end + buildParams(obj[j], (prefix ? (prefix+"["+j.replace("[]", "")+"]"+postfix) : j) ); + } } else { - add( j, jQuery.isFunction(a[j]) ? a[j]() : a[j] ); + add( prefix, jQuery.isFunction(obj) ? obj() : obj ); } } + buildParams(a); } // Return the resulting serialization