【发布时间】:2016-06-22 20:52:54
【问题描述】:
我正在使用 angularjs http post 在单击按钮时从 Web Api 下载文件。我的代码在 Google Chrome 和 Firefox 中运行良好,但在 Internet Explorer 中无法运行。这是我的代码
$scope.CallApi = function () {
$http({
url: some url,
dataType: 'json',
method: 'POST',
data: null,
responseType: 'arraybuffer',
}).success(function (responsedata, status, xhr) {
var file = xhr('Content-Disposition');
console.log(file);
var filename = file.substr(21, 7);
$scope.value = responsedata;
var fileName = filename;
var blob = new Blob([responsedata], { type: "application/octet-stream" });
var url = URL.createObjectURL(blob);
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
a.href = url;
a.download = fileName;
}).error(function (error) {
alert("Error Found" + " : " + error);
});
};
上面的代码在 IE 中不起作用,我不想使用 FileSaver.js 扩展名是否有任何其他方法可以从 Internet Explorer 中的 api 下载文件。下面我附上了我在 Internet Explorer 中遇到的错误的屏幕截图...... 提前谢谢你.....
【问题讨论】:
-
对不起,我在中间插入了图片....
标签: javascript angularjs