Advertisement
GATE-MST

GATE-MST: working Popular Movie search page using TMDB's api

Jun 30th, 2023 (edited)
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 4.10 KB | Source Code | 0 0
  1. <!doctype html>
  2. <html lang="en">
  3.  
  4. <head>
  5.     <meta charset="utf-8">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1">
  7.     <title>Bootstrap demo</title>
  8.     <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"
  9.        integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous">
  10.  
  11.  
  12.     <style>
  13.        
  14.     </style>
  15.  
  16. </head>
  17.  
  18. <body>
  19.  
  20.     <nav class="navbar navbar-expand-lg navbar-light bg-light">
  21.         <div class="container-fluid">
  22.             <a class="navbar-brand" href="#">Navbar</a>
  23.             <button class="navbar-toggler" type="button" data-bs-toggle="collapse"
  24.                data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false"
  25.                aria-label="Toggle navigation">
  26.                 <span class="navbar-toggler-icon"></span>
  27.             </button>
  28.             <div class="collapse navbar-collapse" id="navbarSupportedContent">
  29.                 <ul class="navbar-nav me-auto mb-2 mb-lg-0">
  30.                     <li class="nav-item">
  31.                         <a class="nav-link active" aria-current="page" href="#">Home</a>
  32.                     </li>
  33.                     <li class="nav-item">
  34.                         <a class="nav-link" href="#">Link</a>
  35.                     </li>
  36.                     <li class="nav-item dropdown">
  37.                         <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button"
  38.                            data-bs-toggle="dropdown" aria-expanded="false">
  39.                             Dropdown
  40.                         </a>
  41.                         <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
  42.                             <li><a class="dropdown-item" href="#">Action</a></li>
  43.                             <li><a class="dropdown-item" href="#">Another action</a></li>
  44.                             <li>
  45.                                 <hr class="dropdown-divider">
  46.                             </li>
  47.                             <li><a class="dropdown-item" href="#">Something else here</a></li>
  48.                         </ul>
  49.                     </li>
  50.                     <li class="nav-item">
  51.                         <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
  52.                     </li>
  53.                 </ul>
  54.                 <form class="d-flex">
  55.                     <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
  56.                     <button class="btn btn-outline-success" type="submit">Search</button>
  57.                 </form>
  58.             </div>
  59.         </div>
  60.     </nav>
  61.  
  62.     <div class="container-fluid">
  63.         <h1>Popular Movies</h1>
  64.         <div id="movielist"></div>
  65.     </div>
  66.  
  67.  
  68.     <script src="https://code.jquery.com/jquery-3.7.0.min.js"
  69.        integrity="sha256-2Pmvv0kuTBOenSvLm6bvfBSSHrUJ+3A7x6P5Ebd07/g=" crossorigin="anonymous"></script>
  70.     <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"
  71.        integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz"
  72.        crossorigin="anonymous"></script>
  73.  
  74.     <script>
  75.         $(function () {
  76.  
  77.             // function to load popular movies from TMDB on document ready
  78.             var api_key = "ce283f8ff68c019530c5f5ccf045de2d"; //TODO insert your unique API KEY here
  79.             var api_url = "https://api.themoviedb.org/3/movie/popular?api_key=" + api_key;
  80.             $.getJSON(api_url, function (data) {
  81.                 $.each(data.results, function (i, item) {
  82.                     console.log(item)
  83.                     var posterFullUrl = "https://image.tmdb.org/t/p/w185//" + item.poster_path;
  84.                     var img = "<img src='" + posterFullUrl + "' title='" + item.title + " (" + item.release_date.substring(0, 4) + ")'/>";
  85.                     $("#movielist").append(img);
  86.                     $("#movielist_title").text("Popular Movies");
  87.                 });
  88.             });
  89.  
  90.  
  91.  
  92.         });
  93.     </script>
  94.  
  95. </body>
  96.  
  97. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement