Here is the source directly from jQuery ( MIT license ):
jQuery.param = function( a, traditional ) {
var prefix,
s = [],
add = function( key, value ) {
value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );
s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
};
if ( traditional === undefined ) {
traditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
}
if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
jQuery.each( a, function() {
add( this.name, this.value );
});
} else {
for ( prefix in a ) {
buildParams( prefix, a[ prefix ], traditional, add );
}
}
return s.join( "&" ).replace( r20, "+" );
};
source
share