JQuery 1.4.2 JSON format that breaks down what was used to work in 1.3.2

I just upgraded jQuery from 1.3.2 to 1.4.2, and I think this gives me some problems. I have a function $.post() , which calls the controller method and passes on some data, which I format like this:

 $.post(url, { arrayParam: myArray, param2: false }, someCallback, 'html'); 

In Firebug, POST says the parameters in 1.3.2 are as follows:

 arrayParam: 100 arrayParam: 101 (etc..) 

But for 1.4.2 they look like this:

 arrayParam[]: 100 

This crashes my controller expecting a List<Int32> for arrayParam (and causes some JSON problems around the codebase). Is there any way around this without returning to 1.3.2 or reprogramming all my controllers?

thanks

+4
source share
1 answer

As with 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 setting jQuery.ajaxSettings.traditional = true; .

jQuery ajax methods use $ .param () for transferred data.

See jquery param for details.

Here is your fix:

 jQuery.ajaxSettings.traditional = true; 
+9
source

Source: https://habr.com/ru/post/1306411/


All Articles