| 775 | }); |
| 776 | |
| 777 | function buildParams( prefix, obj, traditional, add ) { |
| 778 | if ( jQuery.isArray( obj ) ) { |
| 779 | // Serialize array item. |
| 780 | jQuery.each( obj, function( i, v ) { |
| 781 | if ( traditional || rbracket.test( prefix ) ) { |
| 782 | // Treat each array item as a scalar. |
| 783 | add( prefix, v ); |
| 784 | |
| 785 | } else { |
| 786 | // If array item is non-scalar (array or object), encode its |
| 787 | // numeric index to resolve deserialization ambiguity issues. |
| 788 | // Note that rack (as of 1.0.0) can't currently deserialize |
| 789 | // nested arrays properly, and attempting to do so may cause |
| 790 | // a server error. Possible fixes are to modify rack's |
| 791 | // deserialization algorithm or to provide an option or flag |
| 792 | // to force array serialization to be shallow. |
| 793 | buildParams( prefix + "[" + ( typeof v === "object" || jQuery.isArray(v) ? i : "" ) + "]", v, traditional, add ); |
| 794 | } |
| 795 | }); |
| 796 | |
| 797 | } else if ( !traditional && obj != null && typeof obj === "object" ) { |
| 798 | // Serialize object item. |
| 799 | for ( var name in obj ) { |
| 800 | buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add ); |
| 801 | } |
| 802 | |
| 803 | } else { |
| 804 | // Serialize scalar item. |
| 805 | add( prefix, obj ); |
| 806 | } |
| 807 | } |
| 808 | |
| 809 | // This is still on the jQuery object... for now |
| 810 | // Want to move this to jQuery.ajax some day |