sim*_*ott 4 node.js express sails.js
在我的html页面中,我将此帖子发送到我的sails服务器,但由于req.param()函数没有返回任何有意义的答案,我无法访问控制器中的数据.
这是网页代码
$.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"));
});
Run Code Online (Sandbox Code Playgroud)
这是控制器
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: {}
};
Run Code Online (Sandbox Code Playgroud)
我尝试过使用req.body,但似乎不包含任何内容.这是我在输出中得到的
batch called
req.body=[object Object]
TypeError: Cannot convert object to primitive value
at Array.toString (native)
Run Code Online (Sandbox Code Playgroud)
mdu*_*sch 12
module.exports = {
batch: function (req, res, next){
console.log("batch called");
console.log(req.body);
console.log(req.param("batch"));
res.send("ok");
},
_config: {}
};
Run Code Online (Sandbox Code Playgroud)
如果使用console.log("foo" + object)nodejs将尝试将obeject转换为字符串.简单地做console.log(object)
| 归档时间: |
|
| 查看次数: |
11750 次 |
| 最近记录: |