我想知道是否有办法在 Node.js 中呈现页面,然后在 2 秒后重定向到另一个页面。其中的一些内容:
app.get('/thankyou',function(req,res){
res.render('thankyou' {message : 'Thank you for your submission'});
//after 2 seconds
res.redirect('nextpage');
});
您必须在模板中执行此操作。服务器代码变为:
app.get('/thankyou',function(req,res){
res.render('thankyou' {message : 'Thank you for your submission'});
});
并在模板中添加:
<script>
setTimeout(function () {
// after 2 seconds
window.location = "/next-page";
}, 2000)
</script>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句