Express 4.2.0 post 为何不能解析参数呢。

2014-06-28 08:59:56 +08:00
 0x001
router.post('/', function(req, res) {
console.log(req.body);
console.log(req.body.name);
console.log(req.body.tel);
res.send("ok");
});


下面是log:
{}
undefined
undefined
POST / 200 2ms - 2b
5454 次点击
所在节点    Node.js
7 条回复
coolicer
2014-06-28 09:09:34 +08:00
你加了body-parser没有
coolicer
2014-06-28 09:10:21 +08:00
83053187 新手群欢迎你。
0x001
2014-06-28 09:18:51 +08:00
@coolicer 我用express创建的工程,加了body-parser的
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
WildCat
2014-06-28 10:16:10 +08:00
试试
req.param('name')
breeswish
2014-06-28 10:21:24 +08:00
req.body: body
req.param: query string
RaymondYip
2014-06-29 23:35:14 +08:00
Req.query
acecode
2014-06-30 10:30:50 +08:00
要不console.log( util.inspect(req, 3, 4, true) )看看?

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/119935

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX