Integration of Mike Alsup's excellent form serialization code. The benefits are as...
[jquery.git] / src / ajax / ajax.js
index dd54d0c..ffe3048 100644 (file)
@@ -62,9 +62,25 @@ jQuery.fn.extend({
        },
 
        serialize: function() {
-               return jQuery.param( this );
-       }
-
+               return jQuery.param(this.serializeArray());
+       },
+\r      serializeArray: function() {\r
+               return this.map(function(){
+                       return jQuery.nodeName(this, "form") ?
+                               jQuery.makeArray(this.elements) : this;
+               })
+               .filter(function(){
+                       return this.name && !this.disabled && 
+                               (this.checked || /select|textarea/i.test(this.nodeName) || 
+                                       /text|hidden|password/i.test(this.type));
+               })
+               .map(function(i, elem){\r                        var val = jQuery(this).val();
+                       return val == null ? null :
+                               val.constructor == Array ?
+                                       jQuery.map( val, function(i, val){\r                                             return {name: elem.name, value: val};
+                                       }) :
+                                       {name: elem.name, value: val};\r
+               }).get();\r      }
 });
 
 // Attach a bunch of functions for handling common AJAX events
@@ -440,7 +456,7 @@ jQuery.extend({
                                        s.push( encodeURIComponent(j) + "=" + encodeURIComponent( a[j] ) );
 
                // Return the resulting serialization
-               return s.join("&");
+               return s.join("&").replace(/%20/g, "+");
        }
 
 });