I am attempting to extract JSON data from http://omadbapi.com/?s=
for a search script, but I am encountering difficulties in retrieving the Title element from this particular JSON:
{
"Search": [{
"Title": "Sherlock Holmes: A Game of Shadows",
"Year": "2011",
"imdbID": "tt1515091",
"Type": "movie"
},{
"Title": "Spy Kids 3-D: Game Over",
"Year": "2003",
"imdbID": "tt0338459",
"Type": "movie"
}]
}
Here is the JavaScript code snippet:
$(document).ready(function () {
var url = 'http://www.omdbapi.com/?',
mode = 's=',
input,
movieName;
$('button').click(function() {
var input = $('#movie').val(),
movieName = encodeURI(input);
$.getJSON( url + mode + input, function( data ) {
$.each(data, function(e, p) {
document.getElementById("item").innerHTML="Title : " + p.Title;
});
});
});
});
The challenge lies in retrieving p.Title
or data.Title
from the JSON data that is returned. How can this be achieved?