3

I would like to know where I can find the implementation code for jquery.param.

Rob
45.9k24 gold badges126 silver badges155 bronze badges
asked Jul 20, 2010 at 4:20

3 Answers 3

6
answered Jul 20, 2010 at 4:24

Comments

2

Here is the source directly from jQuery (MIT license):

jQuery.param = function( a, traditional ) {
 var prefix,
 s = [],
 add = function( key, value ) {
 // If value is a function, invoke it and return its value
 value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );
 s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
 };
 // Set traditional to true for jQuery <= 1.3.2 behavior.
 if ( traditional === undefined ) {
 traditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
 }
 // If an array was passed in, assume that it is an array of form elements.
 if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
 // Serialize the form elements
 jQuery.each( a, function() {
 add( this.name, this.value );
 });
 } else {
 // If traditional, encode the "old" way (the way 1.3.2 or older
 // did it), otherwise encode params recursively.
 for ( prefix in a ) {
 buildParams( prefix, a[ prefix ], traditional, add );
 }
 }
 // Return the resulting serialization
 return s.join( "&" ).replace( r20, "+" );
};
Daniel Imms
50.5k19 gold badges157 silver badges170 bronze badges
answered Apr 29, 2015 at 13:28

3 Comments

Welcome to Stack Overflow! Code-only answers are discouraged. Can you edit your post to describe where you got this code, perhaps?
This is probably a correct answer, however, the lack of a source means that 1) no context is provided and 2) is very susceptible to be outdated. A link and a little explanation would improve this answer a lot
Please explain where you got the source from in the future, simply pasting the code here and claiming it as your own is against the jQuery license. I added proper attribution.
0

In case anyone else stumbles across this, it's in src/serialize.js now https://github.com/jquery/jquery/blob/master/src/serialize.js

answered Mar 14, 2016 at 14:09

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.