Opened 15 years ago
Closed 15 years ago
#1814 closed enhancement (wontfix)
$.param add parameter 'clean' to filter out empty elements if desired
Reported by: | yereth | Owned by: | flesler |
---|---|---|---|
Priority: | minor | Milestone: | 1.3 |
Component: | ajax | Version: | 1.2.1 |
Keywords: | $.param, clean serialize, filter serialize | Cc: | |
Blocked by: | Blocking: |
Description
I added the following code to my jQuery 1.2.1 version, because for me it's very useful to be able to filter a serialized parameter list to exclude empty values. This is the change (mind the new 'clean' parameter:
// Serialize an array of form elements or a set of // key/values into a query string param: function( a, clean ) { var s = []; // 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(){ if (!clean || $.trim(this.value)) s.push( encodeURIComponent(this.name) + "=" + encodeURIComponent( this.value ) ); }); // Otherwise, assume that it's an object of key/value pairs else // Serialize the key/values for ( var j in a ) // 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(){ if (!clean || $.trim(this)) s.push( encodeURIComponent(j) + "=" + encodeURIComponent( this ) ); }); else '''if (!clean || $.trim(a[j]))''' s.push( encodeURIComponent(j) + "=" + encodeURIComponent( a[j] ) ); // Return the resulting serialization return s.join("&").replace(/%20/g, "+"); }
Is it an idea to include in the core?
Change History (4)
comment:1 Changed 15 years ago by
Component: | core → ajax |
---|
comment:2 Changed 15 years ago by
Owner: | set to flesler |
---|---|
Status: | new → assigned |
comment:3 Changed 15 years ago by
Milestone: | 1.2.2 → 1.3 |
---|---|
need: | Review → Test Case |
comment:4 Changed 15 years ago by
Resolution: | → wontfix |
---|---|
Status: | assigned → closed |
Note: See
TracTickets for help on using
tickets.
Could you provide a situation where filtering these values makes a big change ?