创建blob期间Internet Explorer 11中的InvalidStateError [英] InvalidStateError in internet explorer 11 during blob creation

查看:828
本文介绍了创建blob期间Internet Explorer 11中的InvalidStateError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在blob创建行上得到一个InvalidStateError即11。不用说,它适用于Chrome和Firefox。
我可以看到二进制数据是我的客户端。有没有其他方法可以将其下载为文件?

I'm getting an InvalidStateError at the blob creation line on ie 11. Needless to say, It works in Chrome and Firefox. I can see that the binary data is my client side. Are there any alternatives to download this as a file?

var request= new ActiveXObject("MicrosoftXMLHTTP");
request.open("post", strURL, true);
request.setRequestHeader("Content-type","text/html");
addSecureTokenHeader(request);
request.responseType = 'blob';


request.onload  = function(event) {
if (request.status == 200) {
var blob = new Blob([request.response], {type: 'application/pdf'});
var url = URL.createObjectURL(blob);

var link = document.querySelector('#sim');
link.setAttribute('href', url);
var filename =  request.getResponseHeader('Content-Disposition');
$('#sim').attr("download", filename);
$(link).trigger('click');
fireEvent(link,'click');

}else {
//handle error
}
}


推荐答案

在实例化XmlHttpRequest对象后立即通过设置xhr.responseType =blob获取InvalidStateError后,移动

After getting InvalidStateError by setting xhr.responseType = "blob" right after instantiating the XmlHttpRequest object, moving

xhr.responseType = "blob" 

to

xhr.onloadstart = function(ev) {
    xhr.responseType = "blob";
}

为我解决了! :)

这篇关于创建blob期间Internet Explorer 11中的InvalidStateError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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