req.body.username是未定义
快递JS,我用肢体解析器来获取用户名。当我尝试获取用户名,则返回undefined。谁能帮我?
app.use(session({
cookieName: 'session',
secret: "Shh_It's_a_secret",
duration: 100000 * 100000
}));
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/home', (req, res) => {
if(req.body.username){
res.send('Invalid Username, Press The Back Button To Try Again');
} else if (!req.body.username) {
app.use(express.static(__dirname + '/NerdFestProjectHomepage.html'));
res.sendfile('NerdFestProjectHomepage.html');
console.log(req.body.username);
}
})
当我试图让req.body.username,则返回undefined。
回答如下:这是一个GET请求。在快递,不可能派“身体”使用GET请求。
更改GET到POST请求:
app.post('/home', cb );
并鉴于使用:
<form action="/home" method="POST"></form>
req.body.username是未定义
快递JS,我用肢体解析器来获取用户名。当我尝试获取用户名,则返回undefined。谁能帮我?
app.use(session({
cookieName: 'session',
secret: "Shh_It's_a_secret",
duration: 100000 * 100000
}));
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/home', (req, res) => {
if(req.body.username){
res.send('Invalid Username, Press The Back Button To Try Again');
} else if (!req.body.username) {
app.use(express.static(__dirname + '/NerdFestProjectHomepage.html'));
res.sendfile('NerdFestProjectHomepage.html');
console.log(req.body.username);
}
})
当我试图让req.body.username,则返回undefined。
回答如下:这是一个GET请求。在快递,不可能派“身体”使用GET请求。
更改GET到POST请求:
app.post('/home', cb );
并鉴于使用:
<form action="/home" method="POST"></form>