Response title
This is preview!
jQuery.ajax({ url: "testprocedure", traditional: true, data: { "p_test": "sometext", "p_array": [] } });
testprocedure?p_test=sometextbut in 1.4.4 with
testprocedure?p_test=sometext&p_array=At least in my environment that will generate something completely different on the backend.
var myObject = { b: ["test1","","test3"], c: [] }; console.log('non traditional: '+decodeURIComponent($.param(myObject))); console.log('traditional: '+decodeURIComponent($.param(myObject, true)));
non traditional: b[]=test1&b[]=&b[]=test3&c= traditional: b=test1&b=&b=test3&c=
The "non traditional" encoding defines an empty array entry with b[]= and the empty array parameter "c" just with c=, so for the backend it's easy to distinguish that the value of the parameter "c" isn't an empty array entry because the brackets are missing.But in the "traditional" encoding the empty array entry for "b" is encoded with b= but as well as the empty array "c" which is also encoded with c=. So for the backend it looks like that "c" is an array with one entry which is empty.Do you agree with my above analysis? Based on that I think the pre-1.4.4 behavior was correct that the empty array is omitted if the "traditional" parameter is set for param function. That gives the backend a chance to distinguish an empty array entry and a empty array.I think the new behavior is correct for the "non traditional", but not for traditional.RegardsPatrickPS: Are browser implementations an established standard? Because if you have multiple checkboxes with the same value for the "name" attribute, the browser will build an array and encode all checked checkboxes into the POST request. But it will not add one empty parameter entry if they array is empty as the new implementation of param does.
your answer is strange, it is not because there is no established standaard for how to serialize complex objects, that you can change the way you do it in a next version, because this breaks exisiting behaviour!!!This isn't relevant; any change, even fixing things that are clearly bugs, will break existing behavior. That's why I would prefer to have someone point to a standard or convention, so that when we undo #6481 and someone else's code breaks (like the person reporting #6481 originally) we can point to that standard or convention as the reason why it works the way it does.
© 2013 jQuery Foundation
Sponsored by and others.