Monday, 15 April 2013

jQuery.ajax() omits "empty" object attributes -



jQuery.ajax() omits "empty" object attributes -

i have next js object:

var data_test = { foo: [], bar: [ 'baz' ] };

when submit object via jquery.ajax():

$.ajax({ url: "test.php", type: "post", data: data_test });

it turns out bar array sent, , not foo one.

proof: in test.php var_dumped $_request:

array(1) { ["bar"]=> array(1) { [0]=> string(3) "baz" } }

is possible forcefulness jquery submit empty object attribute? need jquery send exact re-create of data_test object, if omits empty value breaks logic!

a little (very) late game, wanted point out if application ready take json, can send empty arrays using json.stringify:

var data_test = { foo: [], bar: [ 'baz' ] }; $.ajax({ url: "test.php", type: "post", data: json.stringify(data_test), contenttype: 'application/json' });

this should post empty array. beware json.stringify available starting ie8, utilize json.js fill gap.

jquery

No comments:

Post a Comment