为什么我的 JSON status return 0 在 Chrome 中却在 IE 中有效?

Why does my JSON status return 0 in Chrome but in IE it works?

信息:

问题:

<!DOCTYPE html>
<html>
<body>
<h1>Meu Projeto</h1>

<button onclick="math()">Current Math</button>
<div id="teste"></div>
<div id="status"></div>
<div id="readystate"></div>
<script>
identificador = 0;

function math(){
  
var url = "https://br.api.pvp.net/observer-mode/rest/consumer/getSpectatorGameInfo/BR1/974721?api_key=5";
  
document.getElementById("teste").innerHTML = "URL: " + url;
var xmlhttp = new XMLHttpRequest();
  xmlhttp.open("GET", url, true);
  xmlhttp.send();
  xmlhttp.onreadystatechange = function () {

document.getElementById("status").innerHTML = "Status: " + xmlhttp.status;
document.getElementById("readystate").innerHTML = "ReadyState: " + xmlhttp.readyState;
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
     alert("OK");
    }
    if (xmlhttp.readyState == 4 && xmlhttp.status == 401) {
     alert("Unauthorized 401 but OK");
    }
    if (xmlhttp.readyState == 4 && xmlhttp.status == 404) {
     alert("Erro 404 but OK");
    }
    if (xmlhttp.readyState == 4 && xmlhttp.status == 0) {
     alert("status 0 ?");
    }
  }
}

</script>
</body>
</html>

没有为该端点设置 CORS header,特别是 'Access-Control-Allow-Origin' header。因此它是 inaccessible/restricted.

Riot Games API 中的所有端点通常设置这些 header,但 current-game 和 featured-game 端点除外。解决此问题的最简单方法是发出请求 server-side,如果您想要发布您的应用程序,无论如何都必须这样做。