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
The param() method creates a serialized representation of an array or an object. The serialized values can be used in the URL query string when making an AJAX request.
The traditional property changes the way how parameters are sent to the server. As of jQuery 1.8, it is defaulted to false. For ASP.NET MVC developer $. ajax(url, { data : { a : [1,2,3] }, traditional : true })); // `data` are sent as "a=1&a=2&a=3"
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With