JSON请求返回undefined,而不是错误

时间:2016-02-27 20:58:17

标签: javascript json api jsonp

function searchGames(query) {
  // send off the query
  $.ajax({
    url: GamesSearchUrl,
    type : "get",
    data: {
            query : query,
            resources: "game", 
            format: "jsonp", 
            crossDomain: true, 
            limit: 16, 
            field_list : "description,name,image", 
            json_callback : "returnGames",
            sort : "original_release_date:desc"
          },
    dataType: "jsonp"
  });
};
/* Reference: http://stackoverflow.com/questions/22918573/giantbomb-api-work */
/* Reference: http://www.giantbomb.com/forums/api-developers-3017/api-request-with-jsonp-uncaught-syntaxerror-1492639/ */

    // callback for when we get back the results
    function returnGames(data) {
      $('div#display').append('Found ' + data.total + ' results for ' + data.query);
      var games = data.game;
        $.each(games, function(index, game) {
            $('div#display').append('<h1>' + game.name + '</h1>');
            $('div#display').append('<p>' + game.description + '</p>');
            $('div#display').append('<img src="' + game.image + '" />');
        });
    }

上面列出了函数,据我所知,JSONP数据应该传递给returnGames函数,但是页面上的输出是undefined未定义的结果。控制台显示没有错误?

我正在使用巨型炸弹API。查询和GameSearchURL等变量在文档顶部定义为全局变量。函数中的console.log显示变量已正确传递给它。

0 个答案:

没有答案