【发布时间】:2021-08-28 12:30:37
【问题描述】:
如何提取数据?我需要赛道名称、日期、比赛名称、回合、季节和时间
var xhr = new XMLHttpRequest;
xhr.onreadystatechange = function(){
if(this.readyState == 4 && this.status == 200){
var json = JSON.parse(xhr.responseText);
var yourData = json.MRData;
document.getElementById('playlist').innerHTML = yourData;
}
};
xhr.open("GET", "http://ergast.com/api/f1/current/next.json", true);
xhr.send();
【问题讨论】:
-
请添加 JSON 而不是图片。
-
老兄 @HassanImam ,这是 json ergast.com/api/f1/current/next.json
-
变量
json的名称不正确。内容将是一个实际的对象,而不是 JSON。 -
使用这个
const {Circuit: {circuitName}, date, raceName, round, season, time} = obj.MRData.RaceTable.Races[0]
标签: javascript api httprequest