[英]Express.js req.body is undefined
edit:guys I'm genually new to all of this.编辑:伙计们,我对这一切都很陌生。 here's the html form I used.
这是我使用的 html 表格。 should i update this question with something else?
我应该用其他东西更新这个问题吗?
<form action="/pesquisar" method="post">
<input type="text" id="cO">
<input type="text" id="cD">
<input type="submit">
</form>
I'm currently trying to design a simple browser app utilizing express.我目前正在尝试使用 express 设计一个简单的浏览器应用程序。 console.log(req.body) comes back {} and i cant find the solution, been here for the best part of the day lol
console.log(req.body) 回来{},我找不到解决方案,在这里度过了一天中最美好的时光哈哈
Here's my app这是我的应用程序
var express = require('express');
var path = require('path');
var logger = require('morgan');
var bodyParser = require('body-parser');
var app = express();
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(express.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.get('/', function(req, res){
console.log(req.body);
res.render('index', {
infoVoos: 'acesso_inicial'
});
});
app.post('/pesquisar', function(req,res){
console.log("");
console.log("");
console.log(req.body);
res.send('ok');
});
app.listen(3000);
console.log('############');
console.log('Server on');
console.log('');
module.exports = app;
I changed the parameter of the input tag from "id" to "name" and it's working fine now.我将输入标签的参数从“id”更改为“name”,现在它工作正常。
original原来的
<form action="/pesquisar" method="post">
<input type="text" id="cO">
<input type="text" id="cD">
<input type="submit">
</form>
new新的
<form action="/pesquisar" method="post">
<input type="text" name="cO">
<input type="text" name="cD">
<input type="submit">
</form>
thankx guys谢谢各位
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.