Is it good to use jQuery AJAX with traditional true?

心已入冬 提交于 2019-11-30 21:04:30

问题


First, I don't know what traditional means in Ajax setting, Second, is there any case we need set it to be true in ASP MVC?

Based on the name, I believe it's going to be depreciated soon? Isn't it?


回答1:


jQuery API documentation

http://api.jquery.com/jQuery.Ajax/#jQuery-ajax-settings

traditional

Type: Boolean

Set this to true if you wish to use the traditional style of param serialization.

Let's have a look below, tranditional flag changes the way how parameters are sent to the server

For PHP developer

$.ajax(url, {
   data : { a : [1,2,3] },
   traditional : false
}));
// `data` are sent as "a[]=1&a[]=2&a[]=3"

For ASP.NET MVC developer

$.ajax(url, {
   data : { a : [1,2,3] },
   traditional : true
}));

// `data` are sent as "a=1&a=2&a=3"

As you can see, it is important to set traditional flag depending on your server side language.

So I guess, it won't be deprecated anytime in near future.



来源:https://stackoverflow.com/questions/31152130/is-it-good-to-use-jquery-ajax-with-traditional-true

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!