Reputation: 452
I would like to understand how to write sails-js controller when http request looks as below, especially here I am trying to send raw-data with Content-Type: application/json
. Please advise. (I am able to work with POST with form-data, In controller if read req.body I get form-data as key-value pairs of 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);
});
Upvotes: 2
Views: 3341
Reputation: 452
Replacing the data line with this: data: '{ "companyID":"TGDEV","firstName":"Naga","lastName":"A", "otherIDs": [123,345] } '
Upvotes: -1
Reputation: 1288
Try replacing the data line with this:
data: '{ "companyID":"TGDEV","firstName":"Naga","lastName":"A", "otherIDs": [123,345] }'
I think it has something to do with the JSON being invalid. Single quotes are not valid JSON. Check your JSON here if you're unsure, it's a good resource: http://jsonlint.com/
Upvotes: 2