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

6,762 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.

6,762 Points

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


1 Answer

Emmanuel Molina
Emmanuel Molina
9,268 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 ../