【发布时间】:2019-07-01 18:15:07
【问题描述】:
为了清楚起见,我将表格简化为以下内容:
<form method="post" action="/form" id="testform" enctype="application/x-www-form-urlencoded" name="testform" novalidate>
<input type="text" class="form-control" id="name" >
<button type="submit" class="btn btn-dark btn-lg">Generate XML</button>
</form>
在我的主 js 文件中,我有以下内容:
var bodyParser = require('body-parser')
// create application/x-www-form-urlencoded parser
var urlencodedParser = bodyParser.urlencoded({ extended: true })
我正在这里接收数据(或不接收,视情况而定):
.post('/form', urlencodedParser, function (req, res) {
res.send('welcome, ' + req.body.name)
console.log(req.body)
})
我得到的只是“欢迎,未定义”,日志显示为空 - {}
这让我很生气,我该如何检查发送的内容?调试这太疯狂了!
【问题讨论】:
标签: node.js forms express parsing body-parser