Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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);
xhr.open("GET", "data/employees.json");

1 Answer

Charles Wanjohi
Charles Wanjohi
9,235 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!