Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens with in progress Ajax request on page reload [closed]

We have report page from where user can export the reports in CSV. At server in C# MVC we create MemoryStream and write each row after data transformation and finally send response as a File. Browser automatically downloads this files once request complete. As reports takes long time to get generated, user has to wait for it in blocking state.
To tackle this I am sending the Async Ajax request and saving the response as CSV file by creating Blob URL.
This works fine If user stay on report page until all the reports gets downloaded but if the user navigate from report page to other page Ajax request response get lost.
So I have some below questions

  1. What happens with in progress Ajax request on page reload
  2. Does page reload cancel request which was initiated and in progress on the server
  3. What happens with the server response if browser already reloaded page
  4. Is there any way to keep alive such request after reload which needed further
like image 496
Dipak Telangre Avatar asked Dec 18 '22 10:12

Dipak Telangre


1 Answers

  1. The server will continue to compile the report while the user navigates away.

  2. No.

  3. It has nowhere to land. The browser has a 'new' page with no pending requests; it has no knowledge of any prior activity (HTML is stateless).

  4. No. Perhaps you could rig an onBeforeUnload event handler that would warn the user and allow them to stay on the page. But some browsers ignore any event handlers on that event, so it would be hard to make it reliable.

Your best bet is probably an interface change. Put a notice on the page that navigating away will cancel any reports they're waiting for. And give the users an easy way to know their report is being prepared, like an html loading gif.

like image 77
Mike Mannakee Avatar answered Dec 24 '22 00:12

Mike Mannakee