"use strict";
(function() {
var url = "http://api.openweathermap.org/data/2.5/weather?q=London,England";
var apiKey = "OMMITTED FOR PRIVACY REASONS"; // Replace "APIKEY" with your own API key; otherwise, your HTTP request will not work
var httpRequest;
makeRequest();
// create and send an XHR request
function makeRequest() {
httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = responseMethod;
httpRequest.open('GET', url + '&appid=' + apiKey);
httpRequest.send();
}
// handle XHR response
function responseMethod() {
if (httpRequest.readyState === 4) {
console.log(httpRequest.responseText);
}
}
})();
有关错误的屏幕截图,请参见下面的链接,但这是我得到的:
答案 0 :(得分:0)
您的代码看起来不错。我只是用api键替换了您的代码,一切正常(请参见下文)。
您能否更详细地说明出现错误的浏览器? 我尝试使用最新版的chrome和Firefox,没有问题。
{{1}}