【发布时间】:2019-05-02 07:09:08
【问题描述】:
获取 XMLHttpRequest 没有定义,这是我第一次尝试这个东西。使用带有 APi url 的 .open'GET'。
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);
}
【问题讨论】:
-
无法复制。你的代码看起来不错,对我有用。
-
XMLHttpRequest 是浏览器中预定义的对象,后端需要它来安装它的包
-
请指定您正在尝试的环境。您的代码在浏览器上运行良好。
-
@Wendelin 真的吗?幸运...大声笑我不断得到它没有定义。没有意义
-
@zero_two 我必须在 VSCode 中使用它来玩游戏
标签: javascript json xml