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!

4

1 回答 1

0

尝试使用一些引号:

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

或者在外部定义您的数据并像这样分配它:

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

接着 :

$.ajax({
type: 'PUT',
url: model.url(),
data: dataMap,
contentType: 'application/json'
})
于 2013-10-22T01:11:06.617 回答