aboutsummaryrefslogtreecommitdiffstats
path: root/src/ajax.js
diff options
context:
space:
mode:
authorAriel Flesler <aflesler@gmail.com>2008-05-28 02:50:38 +0000
committerAriel Flesler <aflesler@gmail.com>2008-05-28 02:50:38 +0000
commit11761def421412df7ea4d3414310befef450b7ea (patch)
tree1ef8894e66511ee049420be0723df0b0f80a940f /src/ajax.js
parentc6e88b16e9f6e45d87019db45dd04d27482d25d7 (diff)
downloadjquery-11761def421412df7ea4d3414310befef450b7ea.tar.gz
jquery-11761def421412df7ea4d3414310befef450b7ea.zip
jquery ajax: small (misc) improvement to $.param.
Diffstat (limited to 'src/ajax.js')
-rw-r--r--src/ajax.js12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/ajax.js b/src/ajax.js
index eb81e4c48..d7237fc3f 100644
--- a/src/ajax.js
+++ b/src/ajax.js
@@ -486,14 +486,18 @@ jQuery.extend({
// Serialize an array of form elements or a set of
// key/values into a query string
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
// of form elements
if ( a.constructor == Array || a.jquery )
// Serialize the form elements
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
@@ -503,10 +507,10 @@ jQuery.extend({
// If the value is an array then the key names need to be repeated
if ( a[j] && a[j].constructor == Array )
jQuery.each( a[j], function(){
- s.push( encodeURIComponent(j) + "=" + encodeURIComponent( this ) );
+ add( j, this );
});
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 s.join("&").replace(/%20/g, "+");