Syl Syl - 22 days ago 5x
jQuery Question

How do i read a JSON sent by ajax in rails?

I am sending a JS array to my rails app :

url: "/backend/familles/change_order.js",
contentType: 'json',
type: "POST",
data: JSON.stringify(sort_array)

Here is how firefox see the ajax POST :

But a params.inspect only contain the following :

{"controller"=>"backend/familles", "action"=>"change_order", "locale"=>"fr"}

What should I change to be able to read the JSON data?


There is no need to explicitly stringify your data object, jQuery will do that for you! Also you should add a key value for the data you wish to send. Something like this should work:

data: {"sort_array": sort_array}