JavaScript AJAX Basics (retiring) Programming AJAX Parsing JSON Data

ywang04
ywang04
6,733 Points

../data/employees.json and data/employees.json

In the workspace, I found the path for opening an ajax request is:

xhr.open('GET', '../data/employees.json');

But in this video, Dave is using the following path.

xhr.open('GET', 'data/employees.json');

In my local environment, only 'data/employees.json' works fine. '../data/employees.json' throws "404 (Not Found)" error

In the workspace, both of them are ok.

BTW, I have the same directory structure as workspace in my local environment.

Does anyone know the reason? Thanks a lot.

ywang04
ywang04
6,733 Points

Found other students also have the same issue on their own environment.

https://teamtreehouse.com/community/incorrect-url-for-json-data

1 Answer

Emmanuel Molina
Emmanuel Molina
9,265 Points

I guess the script is in js/widget.js so you need to go back one level to access your JSON file ( ../data/employees.json ) If you put your script directly at the root of your folder you don't need the ../