0
我試圖創建一個日誌窗口。我的代碼很簡單。Node.js未定義的屬性
var employees = {
\t '1' : {
\t \t firstName: '',
\t \t lastName: '',
\t \t login: 'qwerty',
\t \t password: '12345',
\t },
\t '2' : {
\t \t login: 'asdfg',
\t \t password: '12345',
\t },
};
app.post('/main', function(req, res) {
\t if (!req.body) return res.sendStatus(400);
\t \t console.log(req.body);
\t for (var key in employees) {
\t \t console.log(key['login']);
\t \t console.log(key['password']);
\t \t if ((key.login == req.body.login) && (key.password == req.body.password)) {
\t \t \t \t res.render('main');
\t \t } else {
\t \t \t app.get('/', function(req,res) {
\t \t \t \t res.send(createIndexPage());
\t \t \t });
\t \t };
\t };
});
爲什麼key.login和key.password返回undefined? 當if語句錯誤時,爲什麼else塊不運行?
謝謝,它的工作原理。但爲什麼當我輸入錯誤的數據頁面是無限加載,否則塊不運行? –