JavaScript AJAX Basics (retiring) Programming AJAX Parsing JSON Data

Brian Patterson
Brian Patterson
19,586 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'GET', 'data/employees.json');
//Step 4 send the request

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,081 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,850 Points

link your js file