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 Processing JSON Data

Chisel Delahanty
Chisel Delahanty
3,609 Points

Finished project files aren't working for me

The employee list is not appearing for me, even when I use the finished project files. I get the following console error message:

Uncaught TypeError: Cannot read property 'inoffice' of undefined at XMLHttpRequest.xhr.onreadystatechange (widget.js:7)

Does anyone have any advice? My full code looks like this:

var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
  if (xhr.readyState === 4) {
    var employees = JSON.parse(xhr.responseText);
    var statusHTML = '<ul class="bulleted">';
    for (var i=0; employees.length; i++) {
      if (employees[i].inoffice === true) {
        statusHTML += '<li class="in">';
      } else {
        statusHTML += '<li class="out">';
      }
      statusHTML += employees[i].name;
      statusHTML += '</li>';
    }
    statusHTML += '</ul>';
    document.getElementById('employeeList').innerHTML = statusHTML;
  }
};
xhr.open("GET", "data/employees.json");
xhr.send();
Steven Parker
Steven Parker
231,269 Points

It might help to see the whole workspace for this one. You could make a snapshot of your workspace and post the link to it here.

Chisel Delahanty
Chisel Delahanty
3,609 Points

Never mind, I found the problem myself – a missing "i <" in my for loop syntax. D'oh!

I'm glad to have gotten the tip about how to make a snapshot of the workspace, though – I hadn't known that. Thanks Steven!

1 Answer

Steven Parker
Steven Parker
231,269 Points

Congratulations on resolving your issue! :+1: