3

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

3 Answers 3

6

/src/ajax.js

Sign up to request clarification or add additional context in comments.

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, "+" );
};

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.