JavaScript AJAX Basics (retiring) Programming AJAX Processing JSON Data

Peter Larson
Peter Larson
6,411 Points

employee list doesn't show up

I re-typed the widget.js file from scratch, being careful to copy the code from the video exactly, and the employee list still doesn't show up.

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;
      statusHTML += '</li>';
    }
    statusHTML += '</ul>';
    document.getElementById('employeeList').innerHTML = statusHTML;
    console.log(statusHTML);
  }
};
xhr.open('GET', 'data/employees.json');
xhr.send();
console.log(statusHTML);

Snapshot: https://w.trhou.se/ctdomp248e

Steven Parker
Steven Parker
171,342 Points

There are other files involved in the display. To facilitate analysis, make a snapshot of your workspace and post the link to it here.

Peter Larson
Peter Larson
6,411 Points

Updated post with a snapshot link

4 Answers

Steven Parker
Steven Parker
171,342 Points

The snapshot did the trick! It did not appear that the script code was ever being loaded, so I added this at line 27 of index.html (just before the line with "</body>"):

  <script src="js/widget.js"></script>

After that, it seems to be working well.

Zoe Campbell
Zoe Campbell
6,288 Points

I keep getting an uncaught syntax error on the last line, does anyone know the reason? https://w.trhou.se/gjhoj5bfnx

Steven Parker
Steven Parker
171,342 Points

It looks like your function is missing the final close brace (perhaps on line 18).

For future questions, always start a fresh question to give yourself the best chance of folks seeing and responding to it. I only saw that because I still had "follow" turned on from the last time I answered.

Steven Parker
Steven Parker
171,342 Points

Please follow the advice I gave to Zoe and start a new question. Also, that's an unsharable direct URL to your workspace, it's temporary and only exists while you are using it. But you can use the snapshot function in the workspace and provide the link to that (not here, in the new question).

Steven Parker
Steven Parker
171,342 Points

Please start a new question

This can be done easily using the "Get Help" button on the page. Then you can delete this "answer".

Vladimir Plokhotniuk
Vladimir Plokhotniuk
5,464 Points

My employee list doesn't show up. https://w.trhou.se/dbj02s8ufu I compared with another answers, but it doesn't helped me

Steven Parker
Steven Parker
171,342 Points

It looks like you already created a new question for this issue, but forgot to post the link to the snapshot there.

I left an answer on that question. Please delete these "answers" from this one.