我试图下载使用Blob进行的ajax调用响应中存在的zip文件,但是我收到错误加载资源失败:帧加载中断。它适用于除Safari之外的所有浏览器。 这是我的代码:
var xhr = new XMLHttpRequest();
xhr.open('GET', url + '?' + params, true);
xhr.setRequestHeader('X-Authorization', 'Token ' + $localStorage.token);
xhr.responseType = 'arraybuffer';
xhr.onload = function(e) {
if (200 <= this.status && this.status < 300) { // success
var content = this.response;
var anchor = document.createElement('a');
var clickEvent = new MouseEvent('click');
anchor.download = projectName + '.zip';
var blob = new Blob([content], {type: 'application/zip'});
anchor.href = URL.createObjectURL(blob);
anchor.dispatchEvent(clickEvent);
}
};
xhr.send();
任何建议?