I'm looking for some help when it comes to ajax. I have written this code.
let api = "http://ift.tt/1mGUATE?
q=city%20name&APPID=307cb175d7f136d2e8f4231faad9dd97"
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
if(this.readyState === 4 && this.status === 200){
let weatherInfo = JSON.parse(this.responseText);
console.log(weatherInfo);
}
else {
console.log('Error: ' + this.status);
}
}
xhr.open("GET", api , true);
xhr.send();
This seems to work fine, however,it will console log the information that I require but it will also console log the "Error" and this.status even though everything has passed. I am just wondering why this happens?
Aucun commentaire:
Enregistrer un commentaire