开发者

DOM exception 11

开发者 https://www.devze.com 2023-04-09 20:41 出处:网络
I\'m running this code via the console on http://TheScoutApp.com on line 3 I\'m getting a DOM exception 11!!!

I'm running this code via the console on http://TheScoutApp.com on line 3 I'm getting a DOM exception 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开发者_C百科/update.xml",true);
xhr2.send();


The property xhr.statusText may only be accessed after the request is finished. But the onreadystatechange-callback gets called erlier - the earlier calls have xhr.readyState==1 (=server connection established).

You have to put the assess of xhr.statusText inside a condition:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号