简体   繁体   中英

Getting “XMLHttpRequest is not defined”

Getting XMLHttpRequest is not defined, this is my first time trying this stuff. Using .open'GET' with an APi url.

 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); } 

我必须添加以下代码段:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM