0

I needed to load and read JSON file with pure JS. It looks like that:

var xmlhttp = new XMLHttpRequest();
var url = "data.json";

xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        data= JSON.parse(xmlhttp.responseText);
    }
};

xmlhttp.open("GET", url, true);
xmlhttp.send();
console.log(data);

I am getting an error saying that data data is not defined. Why?

Bajzel
  • 63
  • 10

0 Answers0