$.getJSON Lab
- Browse to http://omdbapi.com
- Scroll down to Examples
- Search for your favourite movie
- Follow the URL provided to view the Object (JSON)
- Use
$.getJSON(url, callback(data));
to render the movie's Title
and another property on your page.
Lawrence of Arabia Example
$.getJSON('http://shakeitspeare.com/api/poem', function(data) {
console.log(data);
$('body').append(data.poem);
});
$.getJSON('http://www.omdbapi.com/?t=Lawrence+of+Arabia&y=&plot=short&r=json', function(movie) {
var movieArticle = $('<article></article>');
var movieHeader = $('<h1></h1>');
movieHeader.html(movie.Title);
movieArticle.append(movieHeader);
var moviePlot = $('<p></p>');
moviePlot.html(movie.Plot);
movieArticle.append(moviePlot);
$('body').prepend(movieArticle);
});