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

JSON files are not working but non-JSON files are

I'm doing a separate project and I have the following files (among others) in the same folder as my main Javascript file:

hello.js hello.json

When I run the get() function with hello.js, it works. When I run the get() function with hello.json, it does not work.

It shouldn't matter because I'm not actually parsing the data (the callback is just a console.log function), but I also validated that the data in hello.json was valid JSON data.

1 Answer

was this working for you?

$.get('/path/to/file', function(data) {
    console.log(data);
}, 'json');

if not, try something like this

$.getJSON('/path/to/file', function(data) {
    console.log(data);
});