0

I call $.ajax like this :

$.ajax({
  type: 'PUT',
  url: model.url(),
  data: {task: {assigned_to: selected()}},
  contentType: 'application/json'
})

selected() returns an array

it sends request with this payload task%5Bassigned_to%5D%5B%5D=524eda6b421aa91f4e000003&task%5Bassigned_to%5D%5B%5D=524ee37c421aa91ca9000008 and it's wrong! Must send json but it's not json, my rails server can't handle that (Rails MultiJSON).

I tested on chrome and firefox (both on latest stable version).

Any help is really appreciated.

Edit

If I first JSON.stringify data it works fine but that's not a good solution at all, and also $.ajax works in other methods!

KiT O
  • 867
  • 6
  • 21
  • This question is same issue http://stackoverflow.com/q/1749272/1482780 – KiT O Oct 22 '13 at 01:26
  • 1
    Problem will be solved if I set `processData: false` in ajax params. btw why jquery doing that?! why there's an always non-default option in ajax? there must be better solution I think! – KiT O Oct 22 '13 at 01:29
  • might want to checkout out: http://stackoverflow.com/questions/6410810/rails-not-decoding-json-from-jquery-correctly-array-becoming-a-hash-with-intege seems to work for me ;) – aabes Feb 15 '14 at 20:48

1 Answers1

0

Try with some double quotes :

data: {"task": {"assigned_to": selected()}}

Or define your data outside and assign it like this :

var dataMap = {"task": {"assigned_to": selected()}};

and then :

$.ajax({
type: 'PUT',
url: model.url(),
data: dataMap,
contentType: 'application/json'
})
Airrr
  • 11
  • 2