What is "traditional style of param serialization' in JQuery
Do you know what is "traditional style of param serialization" for jQuery.ajax() as mentioned in http://api.jquery.com/jQuery.ajax/ ?
Can you give some introduction?
Thanks
Have a look at the documentation of jQuery.param()
:
As of jQuery 1.4, the
$.param()
method serializes deep objects recursively to accommodate modern scripting languages and frameworks such as PHP and Ruby on Rails. You can disable this functionality globally by settingjQuery.ajaxSettings.traditional = true;
.
Given
var p = {foo: [1,2,3], bar: 42};
setting traditional
to true
generates
foo=1&foo=2&foo=3&bar=42
While e.g. Python can handle these parameters, i.e. it generates a list for foo
, PHP will only consider the last foo
parameter.
But now by default, the result of the serialization is (actually it is URI encoded)
foo[]=1&foo[]=2&foo[]=3&bar=42
which can be better handled, as mentioned, by PHP and RoR.
Or maybe even more interesting is this. Given:
var p = {foo: {1: [3,4], 2:2,3:3}, bar: 42};
traditional produces:
foo=[object Object]&bar=42
which is clearly not useful in comparison with the "new" way:
foo[1][]=3&foo[1][]=4&foo[2]=2&foo[3]=3&bar=42