HTML and CSS Reference
In-Depth Information
10
definition, loads “JSON-encoded data from the server using a
GET
HTTP request.”
We then use the API's URL,
suppled in this case by TMDb
. As with many other APIs, you
11
have to register your application in order to receive a key (a 30-second process). We insert the
API key (
23afca60ebf72f8d88cdcae2c4f31866
) into the URL and pass the user's movie title
into the URL as a search parameter.
One thing to mention is that appending
callback=?
to the end of the URL enables us to make
cross-domain JSON and AJAX calls. Don't forget this, otherwise the data will be limited to your
own domain! This method uses what's called JSONP (or JSON with padding), which basically
allows a script to fetch data from another server on a different domain. To do this, we must
specify the callback above when jQuery loads the data. It replaces the
?
with our custom
function's name, thereby allowing us to make cross-domain calls with ease.