扫码关注官方订阅号
比如表单名为name="post[title]"、name="post[content]",怎样在后台通过
var data = req.body.post; var title = data.title
获取到title
ringa_lee
使用上面的代码的前提是,你安装并使用了了bodyparser中间件,然后就可以使用req.body
req.body
npm install body-parser
var bodyParser = require('body-parser'); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); app.post('/', function(req, res) { var dd = req.body.post; console.log(dd.title); res.json(req.body); });
浏览器显示{"post[title]":"foo","post[content]":"bar"}后台显示undefined,不是我想要的,怎样才能后台打印foo
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
使用上面的代码的前提是,你安装并使用了了bodyparser中间件,然后就可以使用
req.body
npm install body-parser
浏览器显示{"post[title]":"foo","post[content]":"bar"}
后台显示undefined,不是我想要的,怎样才能后台打印foo