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

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);
console.log(employees);

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; } }; xhr.open('GET', 'data/employees.json');

xhr.send();

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
}

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.