Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 485
iviryxavyer Avatar asked Sep 06 '17 17:09

iviryxavyer


1 Answers

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

like image 130
tchan Avatar answered Oct 06 '22 15:10

tchan