HTML and CSS Reference
In-Depth Information
$
.
getJSON
(
"http
:
//api.themoviedb.org/2.1/Movie.search/en/json/
23afca60ebf72f8d88cdcae2c4f31866
/
goonies
?
callback
=?
"
,
function
(
json
) {
$
(
'#poster'
).
html
(
'<h2 class="loading">We'
re afraid nothing was found
for
that search
.
Perhaps you were looking
for
The Goonies
?</
h2
><
img
id
=
"thePoster"
src
=
' + json[0].posters[0].image.url + '
/>
'
);
});
}
Having determined that the API has no results for the user, we could display an error
message. But this being a movie-related Web app, let's give the user a preset poster of The
Goonies and let them know we couldn't find anything. We'll use the exact same
src
attribute
for the image that we used before, this time with
goonies
hardcoded into the API call's URL.
});
}
return
false
;
}
//Because we've wrapped the JSON code in a function, we can call it on
mouse click or on a hit of the Return button while in the input field
$
(
'#search'
).
click
(
getPoster
);
$
(
'#term'
).
keyup
(
function
(
event
){
if
(
event
.
keyCode
==
13
){
getPoster
();
}
});