I'm making a little bit complex page using EJS
and Express.JS
. I'll simplify it a little:
First application loads /update
the easy way and renders it:
app.get('/update', (req, res) => { res.render('update'); });
update
in render
function is an EJS
template. Here's how it looks like:
... <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> ...
As you can see on button click, application loads /perform
express.js
route into specific div
. Here's what it does on Node.JS
side:
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. });
After it returns some content using res.render()
, application starts doing some processes. They take about 1 minute and after completion I want application to redirect to /
. I've tried using res.redirect('/')
etc, but nothing works. Maybe somehow it should tell browser to redirect..
What can I do here?
You load "/perform" via ajax, so you can only send a response (which you do with the res.render('perform'))
So you should do the redirect client side
You can do this with polling, a timeout or even better, you could use socket.io to give a signal from server to client when the actions are done.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.