未定义获取XMLHttpRequest,这是我第一次尝试这种方法。将.open'GET'与APi网址一起使用。
var weatherData;
var request = new XMLHttpRequest();
loadData();
function loadData() {
request.open('GET', 'https://opentdb.com/api.php?amount=5&category=15&difficulty=easy&type=boolean');
request.onload = loadComplete;
request.send();
}
function loadComplete(evt) {
weatherData = JSON.parse(request.responseText);
console.log(weatherData);
}
答案 0 :(得分:1)
我必须添加此代码段:
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;