【发布时间】:2017-11-08 11:30:40
【问题描述】:
我正在使用EJS 和Express.JS 制作一个有点复杂的页面。我稍微简化一下:
第一个应用程序以简单的方式加载 /update 并呈现它:
app.get('/update', (req, res) => {
res.render('update');
});
render 函数中的update 是一个EJS 模板。下面是它的样子:
...
<div id="progress"></div>
<button id="perform" type="button" class="btn btn-default">Download & Update</button>
<script>
$('#perform').click(function() {
$('#perform').hide();
$('#progress').load('/perform');
});
</script>
...
正如您在单击按钮时看到的那样,应用程序加载 /perform express.js 路由到特定的 div。这是它在Node.JS 方面的作用:
app.get('/perform', function(req, res) {
//Renders div
res.render('perform')
//Does some actions in 1-2 minues.
//Here I want it to redirect to / of application.
});
在它使用res.render() 返回一些内容后,应用程序开始执行一些进程。它们大约需要 1 分钟,完成后我希望应用程序重定向到 /。我试过使用res.redirect('/') e.t.c.,但没有任何效果。也许它应该以某种方式告诉浏览器重定向..
我可以在这里做什么?
【问题讨论】:
标签: javascript jquery node.js redirect