Api 如何通过ajax传递数组

Api 如何通过ajax传递数组,api,jquery,Api,Jquery,我想通过Ajax发布以下内容。我该怎么做 <form method="post" action="http://supersaas.com/api/users"> <input type="hidden" id="account" value="robintest"> <input type="hidden" id="id" value="59fk"> <input type="hidden" id="user[name]" name="user[n

我想通过Ajax发布以下内容。我该怎么做

<form method="post" action="http://supersaas.com/api/users">
<input type="hidden" id="account" value="robintest">
 <input type="hidden" id="id" value="59fk"> 
<input type="hidden" id="user[name]" name="user[name]" value="robin@gmail.com">
<input type="hidden" id="user[full_name]" name="user[full_name]" value="thomas">
<input type="hidden" id="user[phone]" name="user[phone]" value="">
<input type="hidden" id="user[address]" name="user[address]" value="">
<input type ="submit" name="submit" value="submit">
</form>
但这会导致语法错误


我需要这样传递变量,因为我要传递给SAAS。因此我无法控制服务器。

您可以像这样传递json对象

data: {account:'sixcreeksTest', id:id,checksome:checksome,user:{name:name,address:address}}
data: {account:'sixcreeksTest', id:id,'user[name]':name,'user[address]':address}
或者,如果需要将其作为表单数据而不是json传递,可以这样做

data: {account:'sixcreeksTest', id:id,checksome:checksome,user:{name:name,address:address}}
data: {account:'sixcreeksTest', id:id,'user[name]':name,'user[address]':address}
尽量避免犯错误

 $.ajax({
   type: "post",
   url: "http://http://www.supersaas.com/api/users",
   data: $('form').serialize(), 
   success: function(result) {
     alert(result);
   }
 });

您的json对于javascript解析器的格式不好,对象的属性名中不允许有[]个签名,Jayantha的第二个解决方案格式正确。