Meteor.http.call客户端结果未定义

时间:2013-04-02 21:26:36

标签: ajax meteor

消费Mashape Airbnb API:

以下内容位于Clients-> airbnb.js文件中。 我的结果未定义。但是使用相同的API,http://jsfiddle.net/ismaelc/FZ5vG/ 工作得很好。

  function getListings(place) {
  alert(place);
  Meteor.http.call("GET", "https://airbnb.p.mashape.com/s",
                  {params : {location:place},
                  headers : {"X-Mashape-Authorization":"ffnGO1suGtJEjqgz4n7ykeuCbDP1hexv"}},
                  function (error, result) {
                    $('#listings').html(EJSON.stringify(result.data));
                    console.log("Status: "+result.statusCode);
                    console.log("Content: "+result.statusCode);
                    console.log("data: "+EJSON.stringify(result.data));
                    console.log("error: "+error.message);
                  }
                );
}

Template.where.events ({
    'click #find': function(event){
      var place = $('#location').val();
      getListings(place);
    }
  });

我的Google Chrome开发人员工具给了我奇怪的HTTP响应。 IMG:http://imgur.com/f5u2C7X

另外,我暂时看到我的console.log然后它就消失了。这是为什么?

1 个答案:

答案 0 :(得分:0)

您可以使用chrome dev工具包中的网络选项卡,确保它在您执行请求之前已经打开,它应该只是添加,您可以查看其文本内容以找到它出错的地方。

enter image description here

响应选项卡应该包含它返回的文本:

enter image description here

值得注意的是,只需检查您的API,您可能需要使用params(HTTP POST参数)而不是data(正文中的JSON帖子),例如{params : {location:place}

相关问题