【问题标题】:Getting "XMLHttpRequest is not defined"获取“未定义 XMLHttpRequest”
【发布时间】: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


【解决方案1】:

我必须添加这个 sn-p:

 var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;

【讨论】:

    猜你喜欢
    • 2021-04-20
    • 1970-01-01
    • 1970-01-01
    • 2019-09-04
    • 1970-01-01
    • 2012-05-25
    • 1970-01-01
    • 2015-12-12
    • 2021-12-27
    相关资源
    最近更新 更多