What´s the difference between traditional:true option and false in Ajax call?

 ̄綄美尐妖づ 提交于 2019-12-08 17:41:52

问题


All of this is for discard a problem with a MVC controller.

This is the code of the ajax:

 $.ajax({
            //tipo de transferencia
            type: "POST",
            //dato a enviar
            dataType: 'Json',
            traditional:true,
            //enviar variable previamente formada contiene la estructura del modelo
            data:data,

            //liga previamente asignada esta liga contiene  la ruta controlador-metodo
            url: url,

Notice the traditional:true.


回答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.

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" 

If traditional was set to false the data would be sent as a%5B%5D=1&a%5B%5D=2&a%5B%5D=3

Answer adapted from neverever from this thread



来源:https://stackoverflow.com/questions/46081486/what%c2%b4s-the-difference-between-traditionaltrue-option-and-false-in-ajax-call

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