用内容types:application / json来启动js http post请求

我想了解如何编写sails-js控制器,当http请求看起来如下,特别是在这里我试图发送与Content-Type: application/json原始数据。 请指教。 (我可以使用forms数据与POST工作,在控制器如果阅读req.body我得到表单数据作为JSON的键值对)

 var settings = { "async": true, "crossDomain": true, "url": "http://localhost:1337/person/create", "method": "POST", "headers": { "content-type": "application/json" }, "data": "{'companyID':'DEV','firstName':'Radha','lastName':'A', 'otherIDs': [123,345] }" } $.ajax(settings).done(function (response) { console.log(response); }); 

尝试用这个replace数据行:

data: '{ "companyID":"TGDEV","firstName":"Naga","lastName":"A", "otherIDs": [123,345] }'

我认为这与JSON无效有关。 单引号不是有效的JSON。 如果您不确定,请在这里查看您的JSON,这是一个很好的资源: http : //jsonlint.com/

replace数据行:data:'{“companyID”:“TGDEV”,“firstName”:“Naga”,“lastName”:“A”,“otherIDs”:[123,345]}'