Javascript XMLHttpRespone为空,状态为0
我试图用下面的代码从java脚本解析XML文档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
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