How to write a file to the response stream and show / hide the "Working" modal window?

I need to export the file to the user. It takes 1-2 minutes to generate a file, so I want the page to go into modal mode with a pad on the page and the "Working" indicator. The problem is that I cannot get the modal things to go away after closing the Save File dialog box.

How can I remove the pad after the dialog is completed?

+3
source share
1 answer

I asked almost the same question a long time ago ( here ), and the famous TJ Crowder offered an amazing solution. The client (page) provides an additional parameter when requesting a file. An optional parameter should be some random string. Then you start your modal dialog "Wait ...".

Now, from the server, when you prepare the answer, you set a cookie for the value of this additional parameter. The client, in turn, must start a timer interval that simply looks at document.cookieevery 100 milliseconds or so, checking this random value. As soon as the cookie contains a random value, you know that the HTTP response came from the server! At this point, you can hide the modal dialog or something else.

+2
source

Source: https://habr.com/ru/post/1792314/


All Articles