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) jQuery and AJAX Stage 3 Challenge Answer

Narendra Joshi
Narendra Joshi
9,905 Points

why 'data' is added as an argument in getJSON callback function?

$.getJSON('../data/rooms.json', function (data) {};

The json that is returned by getJSON will be stored in the data variable

$.getJSON('../data/rooms.json', function(data){
console.dir(data);
});

1 Answer

Bob Swaney
Bob Swaney
13,010 Points

It's the actual data from the JSON file, after being parsed...passed through the callback function...it doesn't havent to be the word 'data'...it could say 'chicken'...or whatever else you want it to...but after we 'GET' the JSON data from the url, the getJSON method parses it and holds onto it...so we then pass it through the callback function so that we can actually manipulate or do something with data.. which is then pass it to the $.each function to be looped through...hope this helps!