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

Brian Patterson
Brian Patterson
19,588 Points

I am getting an error of 404 file not found.

I am getting the above error when following this tutorial.

//Step 1 create an object
let xhr = new XMLHttpRequest();
//Step 2 create the callback
xhr.onreadystatechange = function() {
  if(xhr.readyState === 4) {
    //JSON parse method takes a string and converts it into JS.
    let employees = JSON.parse(xhr.responseText);
    console.log(typeof employees);
  }
};
//Step 3 Opening a request
xhr.open('GET', 'data/employees.json');
//Step 4 send the request
xhr.send();

Not sure why?

3 Answers

Brice Roberts
Brice Roberts
22,415 Points

Have you created the file inside of the data folder inside of workspaces?

A 404 error is a file not found error. The URI for your code seems to be correct, so the file is either not inside of the data folder, or it has not been created yet. Also, make sure that you did not create the file with any capital letters, because the URI is case sensitive.

If this isn't the case, make a snapshot of your workspace in the top right, and post the link here.

Steve Mustanski
Steve Mustanski
15,093 Points

I had the same error except the issue was that I didn't include the js file path in my html file.

Roger Hwang
Roger Hwang
3,851 Points

link your js file