node.js - How to jump to the page after a few seconds after express renders the page?
女神的闺蜜爱上我
女神的闺蜜爱上我 2017-06-24 09:43:30
0
2
1109
  1. I just started learning express and there is a login page. If the verification fails, it will display "The username or password is wrong, please log in again!", and then the page will redirect to the login page after a few seconds, but it has no effect. :

var express = require('express');
var router = express.Router();

router.post('/', function(req, res){
    var username = req.body.user;
    var password = req.body.password;

    if(username === 'liaoyf' && password === '123'){
        res.send('Welcome!' + username);
    }else{
        res.send('用户名或密码错误!请<a href="/">重新登录</a>');
        //这边我想重定向到登录页(登录页路径为/)
        setTimeout(function(){
            res.redirect('/');
        }, 2000);
    }
});

module.exports = router;

Looking online, it seems that send is completed directly and will not be triggered later. So what should be done?

女神的闺蜜爱上我
女神的闺蜜爱上我

reply all(2)
習慣沉默
res.set('refresh', '5;url=http://example.com/');

Or add

in HTML
<meta http-equiv="refresh" content="5;url=http://example.com/" />
淡淡烟草味

You can use res.write() for the previous error message. This will not end the response like send() or end().

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template