jQuery.ajax:“尝试使用不可用或不再可用的对象”

时间:2013-03-14 14:13:39

标签: jquery ajax binary

我正在尝试从服务器读取一些二进制数据,并且这样工作正常:

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)" ...
    }
});

我无法在myHandler中获得结果,因为它返回时出现错误“尝试使用未使用或不再可用的对象”line in jquery source - 显然xhr此时已不再可用。处理这个问题的最佳方法是什么?

在stackoverflow上实际上是一样的:转到/,在firebug控制台中输入:

$.ajax({
        url: "/",
        xhrFields: {
            responseType: "arraybuffer"
        },
        complete: function(xhr) {
            console.log(xhr.readyState);
            console.log(xhr.statusText);
        }
    });

0 个答案:

没有答案