【发布时间】:2015-08-06 09:22:20
【问题描述】:
我有一个 web 服务向我发送一个 excel 文件,调用是通过 Ajax 进行的,逻辑如下:
- 发送“创建文件”请求。
- 询问进度,服务器会返回 0 到 100 之间的数字,客户端会用它更新进度条。
- 收到 100 个更新 iframe 的“src”元素后开始下载
到目前为止,使用 iframe 下载是使用 Internet Explorer 进行下载的唯一方法,所以我想保留它。
这些是我的 iframe 和进度条:
<iframe width="1" height="1" style="display:none" src="{{downloadLink}}"></iframe>
<progressbar class="progress" value="reportProgress" type="success" >
{{reportProgressL}}
</progressbar>
这是我的 Angular js 程序:
$scope.startDownload = function() {
$scope.reportProgress = 0;
$scope.reportProgressL = "0%";
var promise = $http.get('/myServiceCall/createFile');
promise.then(
function(payload){
console.log('success ');
console.log(payload);
},
function(error){
$scope.showAlert('danger',error);
});
$scope.askProgress();
};
$scope.askProgress = function(){
$http.get('/myServiceCall/progress').success(function(response, status, headers, config){
$scope.reportProgress = response.data;
if(response.data < 100){
$scope.reportProgressL = response.data+"%";
$timeout(function() {$scope.askProgress();}, 1000);
}else{
console.log('Server elaboration completed, download should start shortly...');
$scope.reportProgressL = "Done!";
$scope.downloadLink = '/myServiceCall/getFile'; //setting the src iframe attribute: this will start download
}
}).error(function(err, status, headers, config){
alert('Error: '+err+" "+status);
});
};
上面的代码运行良好……但只有一次!除非重新加载页面再次设置“src”属性不会做任何事情。为什么?
【问题讨论】:
标签: javascript angularjs internet-explorer iframe