how to delay a few seconds to jump to another page after express routes to a new page ()
scenario: the wrong user information is entered in the user login interface, and the route to / login, prompts the user information error (expected to be displayed on the page, non-pop-up), N seconds later jump back to the user login interface.
related codes
var pool = require("../pool.js");
var router = express.Router();
router.post("/login", function(req,res){//
console.log(req.body);
var sql = "SELECT * FROM xz_user WHERE uname=? AND upwd=?";//sql,
pool.query(sql, [req.body.uname, req.body.upwd], function(err, result){
if (err)
{
throw err;
}
if (result.length == 0)
{
//res.send(",");
setTimeout(function(){
res.redirect("http://localhost:3000/user_login.html");
}, 3000);
}else
res.send("");
});
});
expected results: 1. User entered username and password error = > 2. Route to / login = > 3. Displays "user does not exist, please log in again" = > 4. Delay N seconds = > 5. Jump back to the login interface
actual result: step 3 cannot be implemented. The code after
res.send ();
is not executed, so how to prompt the user on the routed page that the user does not exist, and then delay the jump back to the login interface?