Serialize keys with empty arrays/object values in jQuery.param(). Fixes #6481.
This commit is contained in:
parent
515efbdc71
commit
7862c45ad2
2 changed files with 15 additions and 5 deletions
13
src/ajax.js
13
src/ajax.js
|
@ -542,7 +542,7 @@ jQuery.extend({
|
|||
});
|
||||
|
||||
function buildParams( prefix, obj, traditional, add ) {
|
||||
if ( jQuery.isArray(obj) ) {
|
||||
if ( jQuery.isArray(obj) && obj.length ) {
|
||||
// Serialize array item.
|
||||
jQuery.each( obj, function( i, v ) {
|
||||
if ( traditional || rbracket.test( prefix ) ) {
|
||||
|
@ -562,10 +562,15 @@ function buildParams( prefix, obj, traditional, add ) {
|
|||
});
|
||||
|
||||
} else if ( !traditional && obj != null && typeof obj === "object" ) {
|
||||
if ( jQuery.isEmptyObject( obj ) ) {
|
||||
add( prefix, "" );
|
||||
|
||||
// Serialize object item.
|
||||
jQuery.each( obj, function( k, v ) {
|
||||
buildParams( prefix + "[" + k + "]", v, traditional, add );
|
||||
});
|
||||
} else {
|
||||
jQuery.each( obj, function( k, v ) {
|
||||
buildParams( prefix + "[" + k + "]", v, traditional, add );
|
||||
});
|
||||
}
|
||||
|
||||
} else {
|
||||
// Serialize scalar item.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue