Javascript XMLHttprequest无法使用twitch.tv api

Javascript XMLHttprequest无法使用twitch.tv api,javascript,api,cors,xmlhttprequest,twitch,Javascript,Api,Cors,Xmlhttprequest,Twitch,因此,我一直在尝试访问twitch.tv api,但每次我提出请求时,都会不断收到错误: "XMLHttpRequest cannot load https://api.twitch.tv/kraken/streams/normalice. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8080' is therefore not al

因此,我一直在尝试访问twitch.tv api,但每次我提出请求时,都会不断收到错误:

 "XMLHttpRequest cannot load https://api.twitch.tv/kraken/streams/normalice. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8080' is therefore not allowed access."
我目前正在开发过程中使用live server软件包,其他方面,我只是使用html、css和javascript。以下是我的javascript:

var req = new XMLHttpRequest();
var url = 'https://api.twitch.tv/kraken/streams/normalice';

req.open("GET", url, true);
req.send();

req.onreadystatechange = function () {
   if (req.status == 200 && req.readState == 4){
      // do stuff here
      console.log('hurray it worked');
   }else{
      console.log(req.statusText);
      console.log(req.responseText);
   }
}

有人知道我为什么会遇到这个错误吗

Twitch.tv API不支持CORS。您需要使用JSON-P又名JSONP来解决这个问题。阅读更多关于这方面的文章。有一个可能有用的链接。

感谢链接提供的帮助!我不敢相信我在文档中漏掉了这个细节。上的评论表明TwitchAPI已经删除了JSONP支持。