我有以下jQuery:
var xj=[{"name":"person","id":1},{"name":"jack", "id":2}];
$.post('/hex-jt/locations',xj , function(data){
console.log("this posted");
},'json');
看起来应该没问题。但这是这样传递给我的rails应用程序的:
知道这是怎么回事吗?
您正在jquery.post()
使用错误的参数数据进行调用,并传递一个数组而不是String或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.
例如,您可以像这样修改它,将数组包装在一个对象中:
xj={"users":[{"name":"person","id":1},{"name":"jack", "id":2}]};
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句