【发布时间】:2019-10-11 09:37:41
【问题描述】:
当我发布这样的表单时,我已经开始学习 node.js 和 express 框架:
router.get('/add-product',(req,res,next)=>{
res.send('<form action="/product" method="POST" ><input type="text" name="title" /><button type="submit">Submit</button></form>');
});
router.post('/product',(req,res,next)=>{
console.log(req.body);
res.redirect('/');
});
当我执行console.log(req.body) 时,它会显示:
[Object: null prototype] { title: 'product' }
而不仅仅是{ title: 'product' }
我想知道这实际上是 express 的错误还是只是最近添加到 express 的一个适当的,因为我下载了去年创建的另一个项目,它使用了相同的方法,当我做 console.log(req.body) 时,它显示相同的输出。
【问题讨论】:
-
将您的 url 编码 bodyparser 扩展为 true 而不是 false,这样就可以了。
标签: angular javascript node.js express