gpt4 book ai didi

javascript - DOM异常11

转载 作者:行者123 更新时间:2023-11-28 16:27:06 24 4
gpt4 key购买 nike

我通过 http://TheScoutApp.com 上的控制台运行此代码在第 3 行我收到 DOM 异常 11!!!

var xhr2 = new XMLHttpRequest();
xhr2.onreadystatechange = function() {
console.error(xhr2.statusText); //DOM exception 11!!!
if (xhr2.readyState === 4 && xhr2.status === 200) {
console.error('xhr2');
}
}
xhr2.open("GET","http://thescoutapp.com/extension/update.xml",true);
xhr2.send();

最佳答案

属性 xhr.statusText 只能在请求完成后才能访问。但是 onreadystatechange-callback 被调用得更早 - 早期的调用有 xhr.readyState==1 (=服务器连接已建立)。

您必须将 xhr.statusText 的值放入条件中:

if(xhr.readyState == 4) {
console.error(xhr.statusText);
}

关于javascript - DOM异常11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7630082/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com