Advertisement
GATE-MST

search movie api script

Jun 30th, 2023
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.99 KB | Source Code | 0 0
  1. // function to search for movies
  2. $("#submit").click(function (e) {
  3.     $("#movielist").empty();
  4.     var search_string = $("#search").val().replace("/ /g", "+");
  5.     // zj: ^^^ this is weird, we're using a "regular expression" to replace *ALL* occurrences of space in that value
  6.     var api_key = "ce283f8ff68c019530c5f5ccf045de2d"; //TODO insert your unique API KEY here
  7.     var movie_search_url = "https://api.themoviedb.org/3/search/movie?api_key=" + api_key + "&query=" + search_string;
  8.  
  9.     $.getJSON(movie_search_url, function (data) {
  10.         $.each(data.results, function (i, item) {
  11.             console.log(item);
  12.             var posterFullUrl = "https://image.tmdb.org/t/p/w185//" + item.poster_path;
  13.             var img = "<img src='" + posterFullUrl + "' title='" + item.title + " (" + item.release_date.substring(0, 4) + ")'/>";
  14.             $("#movielist").append(img);
  15.             $("#movielist_title").text("Search results for '" + search_string + "':");
  16.         });
  17.     });
  18.  
  19. });
Tags: api jQuery
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement