【发布时间】:2020-03-14 14:59:12
【问题描述】:
我对节点 js 很陌生 我已创建代码
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.urlencoded({extended: false}));
app.use('/add-product' ,(req, res, next) => {
res.send('<form action="/product" method="POST"><input type="text" name="title"><button type="submit">Submit</button></form>');
});
app.use('/product' ,(req, res, next) => {
console.log(req.body);
res.redirect('/');
});
app.use('/' ,(req, res, next) => {
res.send("<h1>Hello Express!</h1>");
});
app.listen(3000);
它给了我输出
[Object: null prototype] { title: 'book' }
输出应该是
{ title: 'book' }
我试过这个how to fix [Object: null prototype] { title: 'product' },但它对我不起作用。 尝试链接错误截图:https://www.screencast.com/t/0p9rtUTAsL
请帮帮我!
【问题讨论】:
-
为什么输出对您来说是个问题?它只是告诉你对象的原型是
null。除非您要求原型是特定值,否则这无关紧要。 -
您说您尝试了其他问题的某些内容,但接受的答案清楚地表明这不是问题并解释了原因。这使您的问题更加令人困惑。
标签: javascript node.js express