1 回答

TA貢獻(xiàn)1735條經(jīng)驗(yàn) 獲得超5個(gè)贊
您可以將它們?cè)O(shè)置為全局或?qū)⑺鼈儌鬟f給下一個(gè)函數(shù)
var un, pw1, pw2
var urlencodedParser = bodyparser.urlencoded({extended: false});
app.post('/', urlencodedParser, function(req, res) {
console.log(req.body);
un = req.body.username;
pw1 = req.body.pwd1;
pw2 = req.body.pwd2;
});
或者傳遞它們:
var urlencodedParser = bodyparser.urlencoded({extended: false});
app.post('/', urlencodedParser, function(req, res) {
console.log(req.body);
doSomething(req.body.username, req.body.pw1, req.body.pw2);
});
function doSomething(un, pw1, pw2) {
...
}
添加回答
舉報(bào)