HTML and CSS Reference
In-Depth Information
In the function's callback, we have put the word json (which holds our retrieved data), but we
could have put data or message .
The next check is to see whether any data was returned. TMDb is kind enough to supply us
with a message of “Nothing found” when it can't find anything. So, we've based our if
statement on this string's value.
This check is API-specific. Usually if no results are found, we would expand the object to find a
property named length , which would tell us how many results were returned. If this happens,
the code might look something like this:
if ( json . length != 0 ){
As a side note, before writing even a line of code in the callback function of the JSON call, we
should become familiar with the results returned in Chrome's console or in Firebug. This would
tell us exactly what to check for in if statements and, more importantly, what path to take to
grab the data we want.
Let's add console.log(json); , like so:
$ . getJSON ( "http : //api.themoviedb.org/2.1/Movie.search/en/json/
23afca60ebf72f8d88cdcae2c4f31866/" + film + "?callback=?", function(json) {
console . log ( json );
This will output something like the following in the console of your favorite browser (click the
image to see the full size):
Search WWH ::




Custom Search