Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

202
Views
Getting undefined/no result when printing out api callback

I am trying to run my script that is going to search for a movie title from a movie database. I get results in the console and no errors. But in my renderMovies function it's supposed to store the API movie title, plot etc in my variables, but when I print it out in a list it either gives me nothing (blank) or undefined. I am kind of new to jQuery, AJAX and APIs so I'm following a guide, so the code is not entirely written by me.

OBS: I get undefined when using this $("<td>" + plot + "</td>"), but blank when using $("<td>").append(title). You can find that code in the middle of the renderMovies function.

For example: I search for the movie 'Avatar' and I get two results. However the two results gets "stored" as undefined in the plot description and blank from the title.

$(document).ready(function(){
  $(init);

  function init() {
    $("#searchMovie").click(searchMovie);   
    var movieTitle = $("#movieTitle");
    var table = $("#results");
    var tbody = $("#results tbody");

    function searchMovie(){
      var title = movieTitle.val();

      $.ajax({
        url: "http://www.myapifilms.com/imdb/idIMDB?title=" + title + "&token=b81c6057-20cf-4849-abc4-decbf9b65286&format=json&language=en-us&aka=0&business=0&seasons=0&seasonYear=0&technical=0&filter=2&exactFilter=0&limit=1&forceYear=0&trailers=0&movieTrivia=0&awards=0&moviePhotos=0&movieVideos=0&actors=0&biography=0&uniqueName=0&filmography=0&bornAndDead=0&starSign=0&actorActress=0&actorTrivia=0&similarMovies=0&adultSearch=0&goofs=0&keyword=0&quotes=0&fullSize=0&companyCredits=0&filmingLocations=0", 
        dataType: "jsonp",     
        success: renderMovies
      });
    };

    function renderMovies(movies) {
      console.log(movies);
      tbody.empty();

      for(var m in movies) {
        var movie = movies[m];
        var title = movie.title;
        var plot = movie.simplePlot;
        var posterUrl = movie.urlPoster;
        var imdbUrl = movie.urlIMDB;

        var tr = $("<tr>");
        var titleTd = $("<td>").append(title); // blank 
        var plotTd = $("<td>" + plot + "</td>"); // undefined on my website

        tr.append(titleTd);
        tr.append(plotTd);

        tbody.append(tr);
      }
    }
  }
});
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I've reordered your functions and calls because some of the variables were undefined. (Google Chrome -> F12 (opens developers console))

This returns a response on a button click.

    $(document).ready(function () {

function searchMovie() {
    var movieTitle = $("#movieTitle");
    var title = movieTitle.val();

    $.ajax({
        url: "http://www.myapifilms.com/imdb/idIMDB?title=" + title + "&token=b81c6057-20cf-4849-abc4-decbf9b65286&format=json&language=en-us&aka=0&business=0&seasons=0&seasonYear=0&technical=0&filter=2&exactFilter=0&limit=1&forceYear=0&trailers=0&movieTrivia=0&awards=0&moviePhotos=0&movieVideos=0&actors=0&biography=0&uniqueName=0&filmography=0&bornAndDead=0&starSign=0&actorActress=0&actorTrivia=0&similarMovies=0&adultSearch=0&goofs=0&keyword=0&quotes=0&fullSize=0&companyCredits=0&filmingLocations=0",
        dataType: "jsonp",
        success: renderMovies
    });
}

function renderMovies(movies) {
    console.log(movies);
    var movieInfo = movies.data.movies;

    var table = $("#results");
    var tbody = $("#results tbody");

    tbody.empty();

    for (var m in movieInfo) // Tar information från apin och stoppar in i egna variabler.
    {

        var movie = movieInfo[m];
        var title = movie.title;
        var plot = movie.simplePlot;
        var posterUrl = movie.urlPoster;
        var imdbUrl = movie.urlIMDB;

        var tr = $("<tr>");
        var titleTd = $("<td>").append(title); // blank
        var plotTd = $("<td>" + plot + "</td>"); // undefined on my website

        tr.append(titleTd);
        tr.append(plotTd);

        tbody.append(tr);

    }

}

$("#searchMovie").click(searchMovie);

});
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!