node.js - Posting object array to sails causes 'TypeError: Cannot convert object to primitive value' -
in html page sending post sails server cannot info in controller req.param() function not homecoming meaningful answer.
here web page code
$.post("http://myserver.local/calendar/batch", {"batch":[ { "start_date" : "2014-06-27t09:00:00z", "title" : "abc", "attendees" : [ "fred bloggs", "jimmy jones", "the queen" ], "event_id" : "123", "location" : "horsham, united kingdom", "end_date" : "2014-06-27t10:30:00z" }, { "start_date" : "2014-06-27t09:00:00z", "title" : "another", "attendees" : [ "fred bloggs", "jimmy jones", "the queen" ], "event_id" : "def", "location" : "horsham, united kingdom", "end_date" : "2014-06-27t10:30:00z" } ]}, function (data) { console.log("success"); } ).fail(function(res){ console.log("error: " + res.getresponseheader("error")); });
here controller
module.exports = { batch: function (req, res, next){ console.log("batch called"); console.log("req.body" + req.body); console.log("req.param()" + req.param()); res.send("ok"); }, _config: {} };
i have tried using req.body not seem contain content. in output
batch called req.body=[object object] typeerror: cannot convert object primitive value @ array.tostring (native)
module.exports = { batch: function (req, res, next){ console.log("batch called"); console.log(req.body); console.log(req.param("batch")); res.send("ok"); }, _config: {} };
if utilize console.log("foo" + object) nodejs seek convert obeject string. console.log(object)
node.js express sails.js
No comments:
Post a Comment