-
- // 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 ( a[j] && a[j].constructor == Array )
- jQuery.each( a[j], function(){
- s.push( encodeURIComponent(j) + "=" + encodeURIComponent( this ) );
- });
- else
- s.push( encodeURIComponent(j) + "=" + encodeURIComponent( jQuery.isFunction(a[j]) ? a[j]() : a[j] ) );
+ } else {
+ // 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( prefix, jQuery.isFunction(obj) ? obj() : obj );
+ }
+ }
+ buildParams(a);
+ }