0

我正在使用 OMDb API 来获取一些电影信息。

我使用的功能是这个:

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.";
        }
    });
}

服务器返回的一个示例:

{
   "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"
}

给定的title是参数填写的,omdbapi返回的数据是正确的。只有 data.Poster 不起作用。我究竟做错了什么?

4

1 回答 1

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.";
    }
});
}

试试看它是否有效。您可以参考此链接以获取更多信息。

于 2013-10-31T08:55:07.427 回答