使用xmlhttprequest从多个ID获取API结果

时间:2019-12-16 11:38:28

标签: api xmlhttprequest

我想从多个ID的api中获取多个值 目前,我只能从一个ID中获取结果

<div id="plm"></div>

<script>
var data = null;
var html = "";
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
    if (this.readyState === this.DONE) {
    var data = JSON.parse(this.responseText);

var test = data.api.fixtures[0].homeTeam.logo;
    html += '<img src="'+test+'"/>';

          document.getElementById("plm").innerHTML = html;



    console.log(data.api.fixtures[0]);
    }
});

xhr.open("GET", "https://api-football-v1.p.rapidapi.com/v2/fixtures/id/170071");
xhr.setRequestHeader("x-rapidapi-host", "host");
xhr.setRequestHeader("x-rapidapi-key", "pass");

xhr.send(data);

</script>

我想我需要一个像这样的字符串

var multipleIds = ['170071','170072'];

和GET链接类似于https://api-football-v1.p.rapidapi.com/v2/fixtures/id/ +multipleIds[i]

0 个答案:

没有答案