Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery 1.4.2 JSON format breaking what used to work in 1.3.2

I just upgraded my jQuery from 1.3.2 to 1.4.2, and I think it's giving me some issues. I have a $.post() function that calls a controller method and passes along some data that I format like so:

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

In Firebug, the POST says the parameters in 1.3.2 look like this:

arrayParam: 100
arrayParam: 101 (etc..)

But for 1.4.2 they look like this:

arrayParam[]: 100

This is breaking my controller which is expecting a List<Int32> for arrayParam (and is causing some JSON issues around the codebase). Is there a way around this without either reverting back to 1.3.2 or reprogramming all of my controllers??

Thanks

like image 819
Jason Avatar asked Jan 22 '23 07:01

Jason


1 Answers

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

jQuery's ajax methods use $.param() on the data that is passed in.

See jquery param for more info.

Here is your fix:

jQuery.ajaxSettings.traditional = true;
like image 130
David Murdoch Avatar answered Jan 27 '23 20:01

David Murdoch