I have a web application where users can export results by clicking on a button. As far as I know it isn't possible to initiate a file "download" from javascript, so I use a simple server round trip to start the download:
- User clicks the export button
- Some javascript creates a hidden form field that contains the data I want in the file
- A form submit is triggered
- The servers takes the form data and sends it back to the user as a file
- A file download is triggered
Since uploading the data can take some time, I change the text on the export button to "preparing download" after step 1. Somewhere around step 4 or 5, I want to change the button back to normal. Is there any way to know when the browser starts receiving the response from the post request?