Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // function to search for movies
- $("#submit").click(function (e) {
- $("#movielist").empty();
- var search_string = $("#search").val().replace("/ /g", "+");
- // zj: ^^^ this is weird, we're using a "regular expression" to replace *ALL* occurrences of space in that value
- var api_key = "ce283f8ff68c019530c5f5ccf045de2d"; //TODO insert your unique API KEY here
- var movie_search_url = "https://api.themoviedb.org/3/search/movie?api_key=" + api_key + "&query=" + search_string;
- $.getJSON(movie_search_url, function (data) {
- $.each(data.results, function (i, item) {
- console.log(item);
- var posterFullUrl = "https://image.tmdb.org/t/p/w185//" + item.poster_path;
- var img = "<img src='" + posterFullUrl + "' title='" + item.title + " (" + item.release_date.substring(0, 4) + ")'/>";
- $("#movielist").append(img);
- $("#movielist_title").text("Search results for '" + search_string + "':");
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement