I am currently working on creating a movie search application. This project marks my first time delving into json and I'm facing some issues with my code. As of now, I have it set up and running smoothly on localhost through xampp. On submitting the form
$('.search-form').submit(function (evt) {
// body...
evt.preventDefault();
var $searchBar = $('#search');
var omdbApi = 'http://www.omdbapi.com/?';
var movieSearchTerm = $searchBar.val();
var searchData = {
s:movieSearchTerm,
r:'json'
}
Below is the callback function:
function displayMovies(data) {
// looping through each search result
$.each(data.items,function(i,movie) {
movieHTML += '<li class="desc">';
// including movie title
movieHTML += '<a href="' + movie.Title + '" class="movie-title">';
// adding release year
movieHTML += '<a href="' + movie.Year + '" class="movie-year">';
// displaying movie poster
movieHTML += '<img src="' + movie.Poster + '" class="movie-poster"></li>';
$('#movies').html(movieHTML);
}); // end each
// movieHTML += '</li>';
}
$.getJSON(omdbApi, searchData, displayMovies);
});//end submit