JavaScript AJAX Basics (retiring) Programming AJAX Parsing JSON Data

Nicholas Gaerlan
Nicholas Gaerlan
9,501 Points

Why is my JSON array object "not defined"?

I'm following along in the video and typing everything exactly as shown but when I log things out to the console I get an error

widget.js:7 Uncaught ReferenceError: employees is not defined
    at XMLHttpRequest.xhr.onreadystatechange (widget.js:7)
xhr.onreadystatechange @ widget.js:7
XMLHttpRequest.send (async)
(anonymous) @ widget.js:3

this is a link to my workspace https://w.trhou.se/kdi4xjczd2 and what I have in my widget file:

var xhr = new XMLHttpRequest();

xhr.onreadystatechange = function () {
    if(xhr.readyState === 4) {
        let empoloyees = JSON.parse(xhr.responseText);
        console.log(employees);
    }
};
xhr.open("GET", "data/employees.json");
xhr.send();

1 Answer

Charles Wanjohi
Charles Wanjohi
7,668 Points

Mispell in your declaration

let  empoloyees // note this is not employees

Hope it helps.Regards,

Nicholas Gaerlan
Nicholas Gaerlan
9,501 Points

i saw it right after I posted the question haha. thanks!