我有这样的表格:
form(method="POST", action="/contato")
.row
.col-sm-4.form-group
label NOME
input(type="text",name="contato[nome]").form-control
.col-sm-4.form-group
label TELEFONE
input(type="text",name="contato[telefone]").form-control
.row
.col-sm-4.form-group.btn-group
input(type="submit", value="Salvar").btn.btn-success
a(href="/contato").btn.btn-primary Voltar
但在我的路线中:
router.post('/contato', (req, res) => {
console.log('body', req.body);
});
输出:
body {' contato [nome]':' Rafael',' contato [telefone]':' 0000' }
但我想:
body { contato : { nome : 'Rafael', telefone : '0000' }}
这是怎么回事?
答案 0 :(得分:1)
添加bodyParser
中间件可能有所帮助:
var bodyParser = require('body-parser');
....
....
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
确保你们两个都有!
我收到了这个请求正文:
body { contato: { nome: 'oleg', telefone: '123456' } }