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

Receiving a 404 for the JSON file

Using Chrome, I'm receiving a 404 when I try to grab the Employee List JSON file 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; i<employees.length; i+=1) {
      if (employees[i].inoffice === true) {
        statusHTML += '<li class="in">';
      } else {
        statusHTML += '<li class="out">';
      }
      statusHTML += employees[i].name + '</li>';
    }
    statusHTML += '</ul>';
    document.getElementById('employeeList').innerHTML = statusHTML;
  }
};

xhr.open('GET', '..data/employees.json');
xhr.send();

I also tried switching it to just data/employees.json as shown in the video, but receiving 404 there as well. Am I missing something simple?

2 Answers

Colin Bell
Colin Bell
29,679 Points

is

xhr.open('GET', '..data/employees.json');

supposed to be this?

xhr.open('GET', '../data/employees.json');
                // ^ Missing slash.  

Tried that variation as well, but still getting a 404 (screenshot: http://d.pr/i/jmyk). Either way, it's cleared up for the challenge which is the next video so not a huge deal. Just wasn't sure if I mistyped something somewhere.

Jonathan Leon
Jonathan Leon
18,813 Points

Actually I had this problem too and I found you do not need to dir back for the file as it searches for it on the main host, so you can go straight to data/ , correct me if I'm wrong.