You can do it as follows:
- When the user presses the button the server starts the task, and then sends a response to the client, possibly a "please wait..." type page. Along with the response the server must include a task id that references the task accessible to Javascript.
- The client uses the task id to poll the server regarding task completion status through ajax. Let's say this is route
/status/<taskid>
. This route returnstrue
orfalse
as JSON. It can also return a completion percentage that you can use to render a progress bar widget. - When the server reports that the task is complete the client can issue the redirect to the completion page. If the client needs to be told what is the URL to redirect to, then the status route can include it in the JSON response.
I hope this helps!