1

我正在玩烂番茄 api 和 Meteor。如果我使用$.ajax调用 RT api,我会得到预期的结果。但是,如果我使用 Meteor 方法和 http get,我会得到似乎是 unicode 或其他东西的东西。

在客户端这里是代码。一个事件使用 ajax,另一个使用 Meteor 方法。

Template.hello.events({
  'keyup .search-movies' : function (e, t) {      
    Meteor.call('getMovies', $(e.currentTarget).val(), function(err, resp){
      if(err) console.log(err);
      else console.log(resp);
    });
  },
  'click .click': function(e){
    $.ajax({
      url: "http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=XXX&q=Toy+Story+3&page_limit=1",
      dataType: 'jsonp',
    }).done(function(result) {
      console.log(result);
    });
  }
});

在 Meteor 方法的服务器上

Meteor.methods({
    getMovies: function(query){ 
        var result = HTTP.call("GET", "http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=XXX&q=Toy+Story+3&page_limit=1");
        if (result.statusCode === 200) {
            //var respJson = JSON.parse(result.content);
            console.log(result.content);
            return result.content;
        } 
    }
});

ajax的结果很好,

{"total":1,"movies":[{"id":"770672122","title":"Toy Story 3","year":2010,"mpaa_rating":"G","runtime":103,"critics_consensus":"Deftly blending comedy, adventure, and honest emotion, Toy Story 3 is a rare second sequel that really works.","release_dates":{"theater":"2010-06-18","dvd":"2010-11-02"},"ratings":

但从 http get 不是

I20140209-00:16:27.578(0)?
\u001f�\b\u0000\u0000\u0000\u0000\u0000\u0000\u0003 ...

有人知道发生了什么吗?如果我在做一些愚蠢的事情或遗漏了一些明显的事情,请告诉我。

4

0 回答 0