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

The events .readyState and .onreadystatechange are not working in my Parsing JSON Data workspace. Any suggestions why?

The events are not turning orange in the code as they should be..

var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function (); if(xhr.readyState === 4) { var employees = JSON.parse(xhr.responseText); } }; xhr.open('GET', 'data/employee.json'); xhr.send();

I don't know if this will help. It doesn't seem to be the code. It seems to be a problem with workspace not recognizing events. This code works in Adobe Edge.

Jonathan Archer
Jonathan Archer
9,786 Points

Not sure about the colors (they may have updated the color scheme in Workspace since they did the video—I don't get orange for either of those), but you were missing the curly braces on the xhr.onreadystatechange anonymous function. Maybe that will fix it.

var xhr = new XMLHttpRequest(); 
xhr.onreadystatechange = function () { 
if(xhr.readyState === 4) { 
    var employees = JSON.parse(xhr.responseText); 
} 
}; 
xhr.open('GET', 'data/employee.json'); 
xhr.send();

1 Answer

Huh... It still doesn't work. I also would wonder why they would decide to change the color scheme of the code?? So I decided to move on to the next stage and now the next stage doesn't have any of the files for the what they are working on in workspace. The whole AJAX track has been riddled with glitches for me... I may have to just move on to a whole other section until they fix it. Thanks for the help!

Jonathan Archer
Jonathan Archer
9,786 Points

What lesson are you on specifically? I can copy my exact code here if you let me know.