意外的令牌:使用JSONP请求

时间:2015-12-03 16:04:43

标签: angularjs

我正在尝试通过omdbapi检索电影的imdb评级。

Myy功能看起来像这样,

movieAdd.imdbRating($scope.movieListID.imdb_id)
  .then(function(response){
  console.log (response)
})

我的服务看起来像这样,

function httpPromise (url) {
  var deferred = $q.defer();
  $http({
    method:'JSONP',
    url: url
  })
    .success(function(data){
      deferred.resolve(data);
    })
    .error(function(){
      deferred.reject();
    });
  return deferred.promise;
}

service.imdbRating = function(id_imdb){
  return httpPromise(
    'http://www.omdbapi.com/?i=' + id_imdb + '&plot=short&r'
  )
};

但是在我的控制台中,我在JSONP输出中出现Uncaught SyntaxError: Unexpected token :错误,

{"Title":"Warcraft","Year":"2016","Rated":"N/A","Released":"10 Jun 2016","Runtime":"N/A","Genre":"Action, Adventure, Fantasy","Director":"Duncan Jones","Writer":"Duncan Jones (screenplay), Charles Leavitt (screenplay), Chris Metzen (story)","Actors":"Travis Fimmel, Ben Foster, Paula Patton, Toby Kebbell","Plot":"An epic fantasy/adventure based on the popular video game series.","Language":"English","Country":"USA","Awards":"N/A","Poster":"http://ia.media-imdb.com/images/M/MV5BMTgxMDAzNzMyMV5BMl5BanBnXkFtZTgwNjIwMTgxNzE@._V1_SX300.jpg","Metascore":"N/A","imdbRating":"N/A","imdbVotes":"N/A","imdbID":"tt0803096","Type":"movie","Response":"True"}

0 个答案:

没有答案