![](/img/trans.png)
[英]How to redirect to another page after serving a post request in Node.js?
[英]Redirect to another Node.js page after a period of time
我想知道是否有一種方法可以在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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.