How do I write a file to the response stream and have a 'Working' modal window show/hide?
I need to开发者_JAVA百科 to export a file to the user. It takes 1-2 min to generate the file so I'd like to have the page go into a kind-of modal mode with a layover on the page and a 'Working' spinner showing. The problem is I can't make the modal stuff go away after Save File dialog is closed.
How can I remove the layover after the dialog is done?
I asked pretty much the same question a long time ago (here) and the notable T. J. Crowder suggested an awesome solution. The client (the page) submits an extra parameter when asking for the file. The extra parameter should be some random string. Then, you launch your modal "Wait ..." dialog.
Now, from the server, when you prepare the response, you set a cookie to the value of that extra param. The client, in turn, should start an interval timer that just looks at document.cookie
every 100 milliseconds or so, checking for that random value. As soon as the cookie contains the random value, then you know that the HTTP response has arrived from the server! At that point, you can hide the modal dialog or whatever.
精彩评论