XMLHttpRequest related question

XMLHttpRequest related question
0.0 0

#1

What i dont understand is why after loading the window xml is populated but the weather variable remains undefined
BBcode```

let weather = undefined;

let xml = new XMLHttpRequest();
xml.onreadystatechange = function(){
if(this.readystate == 4 && this.status == 200){
weather = JSON.parse(this.responseText);
}
}
xml.open(‘GET’, https://fcc-weather-api.glitch.me/api/current?lat=33&lon=33, true);
xml.send();

ff2f9473ac24283d74e1cae1990241b2


#2

Your code above should not even run, because you need quotes around GET and the url like:

xml.open('GET', 'https://fcc-weather-api.glitch.me/api/current?lat=33&lon=33, true');

Also, the xml object will not have a property named readystate, but it will have one named readyState.


#3

the url is a template literal so i guess when i copied the code it didnt show up??
but i guess it was a typo. thanks anyway


#4

When I look at the text behind the post, you missed a closing ` at the end of the url.

FYI - When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.