Reputation: 3829
I am sending a JS array to my rails app :
$.ajax({
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?
Upvotes: 0
Views: 55
Reputation: 12643
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}
Upvotes: 1
Reputation: 156
you should use
dataType: 'json'
not contentType
EDIT:
I think you should not send an Array directly. Try:
data: JSON.stringify({"items":sort_array})
or
data: {"items": JSON.stringify(sort_array)}
Upvotes: 1