X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fajax.js;h=4b22205213e386b55e3de04808877b5ba111921f;hb=36ebb4f75ed2d6684c132ddbeb9a05ef015fbc90;hp=7760593d384a36176a007442f27dcbb49ab35349;hpb=f52c4a3d5fb69f143d90f9a032e2a004c36ccae3;p=jquery.git diff --git a/src/ajax.js b/src/ajax.js index 7760593..4b22205 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -524,11 +524,11 @@ jQuery.extend({ // Determines if an XMLHttpRequest returns NotModified httpNotModified: function( xhr, url ) { - var last_modified = xhr.getResponseHeader("Last-Modified"), + var lastModified = xhr.getResponseHeader("Last-Modified"), etag = xhr.getResponseHeader("Etag"); - if ( last_modified ) { - jQuery.lastModified[url] = last_modified; + if ( lastModified ) { + jQuery.lastModified[url] = lastModified; } if ( etag ) { @@ -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