2

我有以下jQuery:

  var xj=[{"name":"person","id":1},{"name":"jack", "id":2}];
  $.post('/hex-jt/locations',xj , function(data){
    console.log("this posted");
  },'json');

看起来应该没问题。但它像这样传递给我的 Rails 应用程序:

在此处输入图像描述

知道这是怎么回事吗?

4

1 回答 1

1

You are calling jquery.post() with bad argument data, passing an array instead of a String or a PlainObject.

jQuery.post( url [, data ] [, success(data, textStatus, jqXHR) ] [, dataType ] )

data
Type: PlainObject or String
A plain object or string that is sent to the server with the request.

You can for instance modify it like this, wrapping the array in an object:

xj={"users":[{"name":"person","id":1},{"name":"jack", "id":2}]};
于 2013-09-07T02:09:53.170 回答