mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
jquery ajax: small (misc) improvement to $.param.
This commit is contained in:
parent
c6e88b16e9
commit
11761def42
10
src/ajax.js
10
src/ajax.js
@ -488,12 +488,16 @@ jQuery.extend({
|
|||||||
param: function( a ) {
|
param: function( a ) {
|
||||||
var s = [ ];
|
var s = [ ];
|
||||||
|
|
||||||
|
function add( key, value ){
|
||||||
|
s[ s.length ] = encodeURIComponent(key) + '=' + encodeURIComponent(value);
|
||||||
|
};
|
||||||
|
|
||||||
// If an array was passed in, assume that it is an array
|
// If an array was passed in, assume that it is an array
|
||||||
// of form elements
|
// of form elements
|
||||||
if ( a.constructor == Array || a.jquery )
|
if ( a.constructor == Array || a.jquery )
|
||||||
// Serialize the form elements
|
// Serialize the form elements
|
||||||
jQuery.each( a, function(){
|
jQuery.each( a, function(){
|
||||||
s.push( encodeURIComponent(this.name) + "=" + encodeURIComponent( this.value ) );
|
add( this.name, this.value );
|
||||||
});
|
});
|
||||||
|
|
||||||
// Otherwise, assume that it's an object of key/value pairs
|
// Otherwise, assume that it's an object of key/value pairs
|
||||||
@ -503,10 +507,10 @@ jQuery.extend({
|
|||||||
// If the value is an array then the key names need to be repeated
|
// If the value is an array then the key names need to be repeated
|
||||||
if ( a[j] && a[j].constructor == Array )
|
if ( a[j] && a[j].constructor == Array )
|
||||||
jQuery.each( a[j], function(){
|
jQuery.each( a[j], function(){
|
||||||
s.push( encodeURIComponent(j) + "=" + encodeURIComponent( this ) );
|
add( j, this );
|
||||||
});
|
});
|
||||||
else
|
else
|
||||||
s.push( encodeURIComponent(j) + "=" + encodeURIComponent( jQuery.isFunction(a[j]) ? a[j]() : a[j] ) );
|
add( j, jQuery.isFunction(a[j]) ? a[j]() : a[j] );
|
||||||
|
|
||||||
// Return the resulting serialization
|
// Return the resulting serialization
|
||||||
return s.join("&").replace(/%20/g, "+");
|
return s.join("&").replace(/%20/g, "+");
|
||||||
|
Loading…
Reference in New Issue
Block a user