@@ -603,20 +603,13 @@ jQuery.extend({
603603 // Serialize an array of form elements or a set of
604604 // key/values into a query string
605605 param : function ( a , traditional ) {
606-
607606 var s = [ ] ;
608607
609608 // Set traditional to true for jQuery <= 1.3.2 behavior.
610609 if ( traditional === undefined ) {
611610 traditional = jQuery . ajaxSettings . traditional ;
612611 }
613612
614- function add ( key , value ) {
615- // If value is a function, invoke it and return its value
616- value = jQuery . isFunction ( value ) ? value ( ) : value ;
617- s [ s . length ] = encodeURIComponent ( key ) + "=" + encodeURIComponent ( value ) ;
618- }
619-
620613 // If an array was passed in, assume that it is an array of form elements.
621614 if ( jQuery . isArray ( a ) || a . jquery ) {
622615 // Serialize the form elements
@@ -627,41 +620,49 @@ jQuery.extend({
627620 } else {
628621 // If traditional, encode the "old" way (the way 1.3.2 or older
629622 // did it), otherwise encode params recursively.
630- jQuery . each ( a , function buildParams ( prefix , obj ) {
631-
632- if ( jQuery . isArray ( obj ) ) {
633- // Serialize array item.
634- jQuery . each ( obj , function ( i , v ) {
635- if ( traditional ) {
636- // Treat each array item as a scalar.
637- add ( prefix , v ) ;
638- } else {
639- // If array item is non-scalar (array or object), encode its
640- // numeric index to resolve deserialization ambiguity issues.
641- // Note that rack (as of 1.0.0) can't currently deserialize
642- // nested arrays properly, and attempting to do so may cause
643- // a server error. Possible fixes are to modify rack's
644- // deserialization algorithm or to provide an option or flag
645- // to force array serialization to be shallow.
646- buildParams ( prefix + "[" + ( typeof v === "object" || jQuery . isArray ( v ) ? i : "" ) + "]" , v ) ;
647- }
648- } ) ;
649-
650- } else if ( ! traditional && obj != null && typeof obj === "object" ) {
651- // Serialize object item.
652- jQuery . each ( obj , function ( k , v ) {
653- buildParams ( prefix + "[" + k + "]" , v ) ;
654- } ) ;
655-
656- } else {
657- // Serialize scalar item.
658- add ( prefix , obj ) ;
659- }
660- } ) ;
623+ for ( var prefix in a ) {
624+ buildParams ( prefix , a [ prefix ] ) ;
625+ }
661626 }
662-
627+
663628 // Return the resulting serialization
664629 return s . join ( "&" ) . replace ( r20 , "+" ) ;
665- }
666630
631+ function buildParams ( prefix , obj ) {
632+ if ( jQuery . isArray ( obj ) ) {
633+ // Serialize array item.
634+ jQuery . each ( obj , function ( i , v ) {
635+ if ( traditional ) {
636+ // Treat each array item as a scalar.
637+ add ( prefix , v ) ;
638+ } else {
639+ // If array item is non-scalar (array or object), encode its
640+ // numeric index to resolve deserialization ambiguity issues.
641+ // Note that rack (as of 1.0.0) can't currently deserialize
642+ // nested arrays properly, and attempting to do so may cause
643+ // a server error. Possible fixes are to modify rack's
644+ // deserialization algorithm or to provide an option or flag
645+ // to force array serialization to be shallow.
646+ buildParams ( prefix + "[" + ( typeof v === "object" || jQuery . isArray ( v ) ? i : "" ) + "]" , v ) ;
647+ }
648+ } ) ;
649+
650+ } else if ( ! traditional && obj != null && typeof obj === "object" ) {
651+ // Serialize object item.
652+ jQuery . each ( obj , function ( k , v ) {
653+ buildParams ( prefix + "[" + k + "]" , v ) ;
654+ } ) ;
655+
656+ } else {
657+ // Serialize scalar item.
658+ add ( prefix , obj ) ;
659+ }
660+ }
661+
662+ function add ( key , value ) {
663+ // If value is a function, invoke it and return its value
664+ value = jQuery . isFunction ( value ) ? value ( ) : value ;
665+ s [ s . length ] = encodeURIComponent ( key ) + "=" + encodeURIComponent ( value ) ;
666+ }
667+ }
667668} ) ;
0 commit comments