Hi! I’m still working on my local weather app. I have gotten a response from the Google Maps API to reverse geocode the coordinates that I get from the browser. I have tried to use that same code in a separate function to get a response from the Dark Sky API. Here is the code:
function getWeatherAPI (apiLinkDS) {
var xhrW = new XMLHttpRequest();
xhrW.open("GET", apiLinkDS);
xhrW.send();
console.log(xhrW.status);
return JSON.parse(xhrW.responseText);
}
For that code I get absolutely no response from the server, but if I am looking at my API usage on my Dark Sky account, the calls are all there.
I have also tried using this code:
function getWeatherAPI (apiLinkDS) {
var xhrW = new XMLHttpRequest();
xhrW.open("GET", apiLinkDS);
xhrW.onload = function() {
if (xhrW.status === 200) {
console.log('User\'s name is ' + xhrW.responseText);
}
else {
console.log('Request failed. Returned status of ' + xhrW.status);
}
}
xhrW.send();
console.log(xhrW.status);
return JSON.parse(xhrW.responseText);
}
From this code I don’t get any sort of response from the if/else statement. I get a response from the second call to the console outside of the if/else, but it’s a response of 0. I have tried to google this response and haven’t been able to find much help. Anyone have any ideas?