Student list showing like this and the problem happened when I click detail button(no req.body data, console.log(req.body) shows []) enter image description here
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});
});
})
I have tried all stuffs from other posts but I don't still get answers for it. I am creating a detail page for students and when I try it, req.body is always empty.(each table's td will have name and age and I want to send it when button clicked) Any ideas for me? Thank you for reading.
It seems that form action does not contain table elements.
just use styled html instead of table (such as div div div!)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.