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
Ajax request
on page reloadThe server will continue to compile the report while the user navigates away.
No.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With