JavaScript AJAX Basics (retiring) Programming AJAX Processing JSON Data

Robert Robinson
Robert Robinson
2,023 Points

Nothing is happening in my browser (chrome), and I can only console.log outside of my function. What am I doing wrong?

I have <script src="js/widget.js"></script> in the head of my html file

var xhr = new XMLHttpRequest();

xhr.onreadystatechange = function () { if(xhr.readystate === 4) {

var employees = JSON.parse(xhr.responseText);

let statusHTML = '<ul class="bulleted>';
for (var=i ; i<employees.length; i += 1){

employees[i] statusHTML += '<li class="in">'; } else { statusHTML += '<li class="out">'; } statusHTML += employees[i].name; statusHTML += '</li>'; } statusHTML += '</ul>'; document.getElementByID('employeeList').innerHTML = statusHTML; } };'GET', 'data/employees.json');


2 Answers

your code isn't formatted that great... but I can see a problem with your for loop, see an example of the structure below

for (var i = 0; i < example.length; i+=1) { 
    //code here
Robert Robinson
Robert Robinson
2,023 Points

Idk why this is but I figured out the solution. Sometimes I have to exit the browser and redo the exercise for it to appear working in my browser. Very inconvenient, but works.