[英]node.js req.body shows empty
学生列表显示如下,当我单击详细信息按钮时发生了问题(没有要求的身体数据,console.log(要求的身体)显示[]) 在此处输入图像描述
student.jade
extends layout
block content
h1 Student list
.studentlist
table
thead
tr
th name
th age
tbody
each mongo_result, i in slist
form(action='/detail', method="POST")
tr
td(type="text" name="name")= mongo_result.name
td(type="text" age="age")= mongo_result.age
button.btn-primary(type="submit" width='50' height='50') Detail
app.js
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(require('stylus').middleware(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'public')));
app.use(app.router);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.bodyParser());
app.post('/detail', (req, res) => {
//var data = res.json({ result: result });
console.log(req.body);
dbs.collection('slist').find({ name: req.body.name, age:1}).toArray((err, docs) => {
if (err) return console.log(err)
console.log(docs);
res.render('detail', { title: 'Detail', year: new Date().getFullYear(), message: 'Detail of student', detail: docs});
});
})
我已经尝试了其他帖子中的所有内容,但仍然没有得到答案。 我正在为学生创建一个详细信息页面,当我尝试该页面时,req.body始终为空。(每个表格的td都有名称和年龄,单击按钮时我想发送它)对我有什么想法? 感谢您的阅读。
似乎表单操作不包含表元素。
只需使用样式化的html而不是表格(例如div div div!)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.