我正在尝试从服务器读取一些二进制数据,并且这样可以正常工作:
var xml = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP");
xml.open("GET", "/some.php", true);
xml.responseType = "arraybuffer";
xml.onreadystatechange = myHandler; // myHandler here seems to be irrelevant
xml.send();
但是,如果我尝试像这样对 jquery 做同样的事情:
$.ajax({
url: "/some.php",
xhrFields: {
responseType: "arraybuffer"
},
complete: function(xhr) {
console.log(xhr.readyState);
console.log(xhr.statusText); // is: [Exception... "An attempt was made to use an object that is not, or is no longer, usable" code: "11" nsresult: "0x8053000b (InvalidStateError)" ...
}
});
我无法得到结果,因为它在 jquery 源代码myHandler
的这一行上返回错误“试图使用一个不可用或不再可用的对象” - 显然此时不再可用. 处理这个问题的最佳方法是什么?xhr
在stackoverflow上实际上是一样的:转到/,在firebug控制台中输入:
$.ajax({
url: "/",
xhrFields: {
responseType: "arraybuffer"
},
complete: function(xhr) {
console.log(xhr.readyState);
console.log(xhr.statusText);
}
});