views:

892

answers:

3

I am downloading a dynamic file in my application, simulating ajax using iframes. What I am doing is, when the download request is made, I will create a dynamic invisible iframe, and set the src of my iframe as the download url.I am able to successfully download the file, but the requirement is to show a download indicator once the download starts and that should finish as soon as the download dialog comes up.I provided call back after iframe creation to show the download indicator, which is successfully working, and provided another method on the 'onload' of the iframe, expecting it will be invoked, when the download dialog comes up. But unfortunately, that is not working, and because of that even after the download completes, my progress indicator is still there. I am not able to remove that. Then I came to realize that the since the content type of the response is not html, it will be served by a separate process, which leads to the download dialog and because of that my onload method is never getting called. Please let me know a solution for this.

A: 

You can use a flash download manager - google will reveal a slew of them.

Your other option is to use real AJAX. Simply make a request to the download URI, and when you get your response, use the responseBody instead of the responseText attribute of the XMLHTTPRequest object.

You'll need a way to write that to the harddrive, which can be done in IE with lax security constraints and the ActiveXObject "Scripting.FileSystemObject" You might be able to use the data uri approach: http://en.wikipedia.org/wiki/Data%5FURI%5Fscheme with a base64 encoding, but I'm not sure if that will work.

Otherwise you're back to flash to write the data you downloaded via ajax to disk.

If you know the size of the dynamic download and exact timing isn't required in the specification, then you could do an internet speed check before the download, add some buffer time to the calculated time it will take to download the file, and just show the dialog box for that given period of time. Very hackish, but then again this scheme seems a little marketing-requires-it-to-be-so-it-shall-be

Marcus Pope
+1  A: 

See this, It might help u

http://code.msdn.microsoft.com/AjaxFileDownload

prasad
A: 

See this, It might help u

http://bytes.com/topic/javascript/answers/610641-file-download-ajax

Diego