Environment: IIS7 / IE / ASP.Net MVC / jQuery
Scenario: when the user clicks the submit button in the webpage, the server will generate an excel file on the fly, then send the file stream back to the client browser, and the user will see the file open/save dialog. But the page stays the same.
In order to add a throbber while the user is waiting for the file to be generated, I have to use ajax to submit the request, otherwise there is no way (or I haven't found any) to know when the file generation is done and in turn hide the throbber.
But ajax cannot receive a file stream (or can it?), so I have to submit another request to get the act开发者_Go百科ual file in the ajax callback, where I can hide the throbber first.
However, since the final request to get the file is automatically done by the code (not a user click), the user will see the yellow info bar which blocks the file download, which is a VERY stupid feature in IE, because after the user right-click the yellow bar and allow the download, they have to generate the file again!
Any idea how to accomplish this?
Thanks
Here's one suggestion:
Fire off an ajax call which creates a memory stream that contains the excel file. Put the memory stream of the excel file into the cache (with a short expiry). Have the ajax call return a "done" string
on the webpage, have you throbber (I'm guessing you mean the spinning waiting animation?) do the animation until it gets the "done" string back from the ajax call which will then fire off another ajax call to grab the excel file. Since the excel file is already in memory, this call should be much faster and you won't need your spinning animation icon.
Note that in step 1, you should keep the expiry short or else a lot of people generating files could fill up your memory fast. You could write to disk too, but you'll need some cleanup method which could get tricky.
精彩评论