0

I am using the OMDb API for getting some film information.

The function I use is this one:

function getImage(titel) { 
    $.ajax({ 
        type: "GET",
        dataType: "json",
        url: "http://www.omdbapi.com/?t=" + titel,
        success: function(data){
            return data.Poster; 
        },
        async:false,
        error: function() {
            return "Image not found.";
        }
    });
}

An example I get returned by the server:

{
   "Title":"The Godfather",
   "Year":"1972",
   "Rated":"R",
   "Released":"24 Mar 1972",
   "Runtime":"2 h 55 min",
   "Genre":"Crime, Drama",
   "Director":"Francis Ford Coppola",
   "Writer":"Mario Puzo, Francis Ford Coppola",
   "Actors":"Marlon Brando, Al Pacino, James Caan, Diane Keaton",
   "Plot":"The aging patriarch of an organized crime dynasty transfers control of his clandestine empire to his reluctant son.",
   "Poster":"http://ia.media-imdb.com/images/M/MV5BMjEyMjcyNDI4MF5BMl5BanBnXkFtZTcwMDA5Mzg3OA@@._V1_SX300.jpg",
   "imdbRating":"9.2",
   "imdbVotes":"755,007",
   "imdbID":"tt0068646",
   "Type":"movie",
   "Response":"True"
}

The titel given is parameter is filled, and the data returned by the omdbapi is correct. Only the data.Poster is not working. What am I doing wrong?

Rémi Benoit
  • 1,307
  • 11
  • 17
user2076160
  • 5
  • 2
  • 8
  • You cannot return data from `success` and `failure` as those functions are not executed in the main loop. How to do Ajax call : http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call – Rémi Benoit Oct 31 '13 at 07:07

1 Answers1

0
function getImage(titel) { 
$.ajax({ 
    type: "GET",
    dataType: "json",
    url: "http://www.omdbapi.com/?t=" + titel,
    success: function(data){
        return $.get(data.Poster); 
    },
    async:false,
    error: function() {
        return "Image not found.";
    }
});
}

Try it and whether it works. You can refer this link to get some more information.

Community
  • 1
  • 1
Madhusudan Joshi
  • 4,438
  • 3
  • 26
  • 42