Javascript XMLHttpRespone为空,状态为0

Javascript XMLHttpRespone为空,状态为0,javascript,xml-parsing,xmlhttprequest,Javascript,Xml Parsing,Xmlhttprequest,我试图用下面的代码从java脚本解析XML文档 var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { if (this.responseXML != null) { Caption(this.video, this.responseXML); } else { throw new Error("Can't read r

我试图用下面的代码从java脚本解析XML文档

var xhr = new XMLHttpRequest();

    xhr.onreadystatechange = function () {

        if (this.responseXML != null) {
            Caption(this.video, this.responseXML);
        } else {
            throw new Error("Can't read resource");
        }

    };
    xhr.video = obj;

    xhr.open("GET", "Br001.xml", true);
    xhr.send("");
但是我得到了
status=0
responseXML=NULL

后续行动:

在如下更改onreadystatechange之后,我得到readyState=1和status=0,responsexml=NULL,并且只得到一个回调

xhr.onreadystatechange = function () {
    if (this.readyState == 4
    && this.status == 200) {

    if (this.responseXML != null) {
        Caption(this.video, this.responseXML);
    } else {
        throw new Error("Can't read resource");
    }
    }
};
在响应可用之前经过多个阶段。您必须等待
readyState
更改为
4

xhr.onreadystatechange = function () {

    if (this.readyState === 4) {
        if (this.responseXML != null) {
            Caption(this.video, this.responseXML);
        } else {
            throw new Error("Can't read resource");
        }
    }

};
最好检查(例如,确保在响应可用之前,它的
200经过多个阶段。您必须等待
readyState
更改为
4

xhr.onreadystatechange = function () {

    if (this.readyState === 4) {
        if (this.responseXML != null) {
            Caption(this.video, this.responseXML);
        } else {
            throw new Error("Can't read resource");
        }
    }

};
最好检查(例如,确保在响应可用之前,它的
200经过多个阶段。您必须等待
readyState
更改为
4

xhr.onreadystatechange = function () {

    if (this.readyState === 4) {
        if (this.responseXML != null) {
            Caption(this.video, this.responseXML);
        } else {
            throw new Error("Can't read resource");
        }
    }

};
最好检查(例如,确保在响应可用之前,它的
200经过多个阶段。您必须等待
readyState
更改为
4

xhr.onreadystatechange = function () {

    if (this.readyState === 4) {
        if (this.responseXML != null) {
            Caption(this.video, this.responseXML);
        } else {
            throw new Error("Can't read resource");
        }
    }

};

最好检查一下(例如,确保它是
200@BrunoLM:谢谢。请随意跳进去看看。@T.JCrowder请检查这个问题,我已经编辑过了。@akshay:如果要从本地驱动器加载文件(例如,
file://...
而不是
http://...
https://...
),大多数浏览器不允许从
file://...
resources。我发现了问题。问题出在路径名上。正在获取readyState=4@BrunoLM:谢谢。请随意加入这些内容。@T.JCrowder请检查问题,我已编辑。@akshay:如果您正在从本地驱动器加载文件(例如,
file://...
而不是
http://...
https://...
),大多数浏览器不允许从
file://...
resources。我发现了问题。问题出在路径名上。正在获取readyState=4@BrunoLM:谢谢。请随意加入这些内容。@T.JCrowder请检查问题,我已编辑。@akshay:如果您正在从本地驱动器加载文件(例如,
file://...
而不是
http://...
https://...
),大多数浏览器不允许从
file://...
resources。我发现了问题。问题出在路径名上。正在获取readyState=4@BrunoLM:谢谢。请随意加入这些内容。@T.JCrowder请检查问题,我已编辑。@akshay:如果您正在从本地驱动器加载文件(例如,
file://...
而不是
http://...
https://...
),大多数浏览器不允许从
file://...
resources。我发现了问题。它与路径名有关。现在获取readyState=4