阿贾克斯文件下载问题 [英] Ajax File download Issue

查看:102
本文介绍了阿贾克斯文件下载问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下载我的应用程序动态的文件,使用内置页框模拟阿贾克斯。我在做什么,当下载请求时,我将创建一个动态的无形的iframe,并设置我的iframe的下载url.I我能够成功下载该文件的src,但要求是要显示一个下载指标一旦下载开始,且应尽快完成在下载对话框出现up.I提供的电话后回iframe的创作显示下载的指标,这是成功的工作,并在iframe的'onload事件提供了另一种方法,希望它会被调用,当下载对话框出现。但不幸的是,这是行不通的,正因为如此下载完成,即使,我的进步指标依然存在。我不能够删除。后来我才意识到,由于响应的内容类型不是HTML,它会通过一个单独的进程,从而导致下载对话框送达,正因为如此我的onload方法永远不会获取调用。请让我知道了一个解决方案。

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.

推荐答案

您应该开始在客户端的计时器,当下载请求是由该测试在指定的时间间隔iframe的状态:

You should start a timer in the client when the download request is made which tests the state of the iframe at a specified interval:

if ( ( iframe.document && iframe.document.readyState == 'complete' )
    || iframe.contentDocument )
{
    stopTimer();
    closePopupDialog();
}

这篇关于阿贾克斯文件下载问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆