I ran into a problem with my JS project. I declared a global variable:
var agencies = {};
And I have a function:
function getAllAgencies() {
let request = new XMLHttpRequest();
request.onreadystatechange = function () {
console.log(this.readyState);
console.log(this.status);
if (this.readyState == 4) {
if (this.status == 200) {
agencies = JSON.parse(request.responseText);
} else {
alert("Greska prilikom ucitavanja agencije!");
}
}
};
request.open("GET", firebase + "/agencije.json", true);
request.send();
}
However, after I call this function it doesn't change the value of the variable agencies, it's still {}.
I checked, it goes into the if statements