GIPHY API and Axios

Asked by At

I'm having some issues returning a GIPHY image to the page. Our homework prompt is to return info from OMDb API along with a matching GIPHY. I'm using axios and I have the javascript returning the movie title and info. The GIPHY API is loading into my console and is referencing the selected movie title from the user input, but I can't quite figure out how to get the GIPHY loaded to my actual page. Any suggestions would be great! I'm thinking it's the way I'm trying to return the GIPHY that I'm not making the right call.

<html lang="en">
  <meta charset="utf-8">
  <title>Movie and GIPHY API</title>
<script src=""></script>
    <link rel="stylesheet" type="text/css" href="style.css">

  <div class="container">
    <h1>Giphy Movie Search</h1>
    <div id="movie-search"></div>
    <!-- This form will be where users input data about the movies -->
    <form class="movie-form">
      <label id="search">Search for a movie</label>
      <input type="text" id="movie-input">
      <!-- This button will trigger our Axios call -->
      <input class="movieBtn" type="submit" value="Search">
<div class="container-one">
    <p id="title">Movie Title:</p>
    <p id="year">Year Released:</p>
    <p id ="genre">Genre:</p>
    <p id="actors">Actors:</p>
    <img id="movie-giphy"></img>
  <script type="text/javascript" src="api.js">

//global variables

//OMDb API set up
var apiMov = "";

//Giphy API set up
var apiGiphy = "";
//here we are setting up our variables to associate with its designated ID 
var input = document.querySelector("#movie-input");
var movieTitle = document.querySelector("#title");
var movieYear = document.querySelector("#year");
var movieGenre = document.querySelector("#genre");
var movieActors = document.querySelector("#actors");
var movieGiphy = document.querySelector("#movie-giphy");


//In this function we are getting the movie data from the OMDb API and returning each aspect of the movie to the page
//Each aspect of the movie will show in it's designated spot
      function getMovieData() {
          axios.get(apiMov + input.value + "&?plot=long")
          .then(function (movieResponse) {
              movieTitle.innerHTML = "Movie Title: " +;
              movieYear.innerHTML = "Year: " +;
              movieGenre.innerHTML = "Genre: " +;
              movieActors.innerHTML = "Actors: " +;
          .catch(function (error) {
              movieTitle.innerHTML = "An error has occured.";
//Here, we are running the function to return the giphy for the movie that is searched
      function getMovieGiphy() {
          axios.get (apiGiphy + input.value)
          .then(function (giphyResponse){
              let gif = document.createElement("img");
                    gif.className = "gif";
                    gif.src =[0].images.original.url;
            movieGiphy.innerHTML = "An error has occured.";

      var button = document.querySelector(".movieBtn");
      button.addEventListener("click", function(){
        // prevent default will keep the page from reloading so your data persists after the event
        // moved this function inside of another function call so that you could prevent the page from loading

0 Answers