您要定义checkTwitter Meteor.method
内部 客户范围的块。因为您不能从客户端调用跨域(除非使用jsonp),所以您必须将此块放在一个
Meteor.isServer块中。
顺便说一句,每个文档,在客户端
Meteor.method的checkTwitter功能仅仅是一个
存根 服务器端方法。您将需要查看文档,以获取有关服务器端和客户端如何
Meteor.methods协同工作的完整说明。
这是http调用的工作示例:
if (Meteor.isServer) { Meteor.methods({ checkTwitter: function () { this.unblock(); return Meteor.http.call("GET", "http://search.twitter.com/search.json?q=perkytweets"); } });}//invoke the server methodif (Meteor.isClient) { Meteor.call("checkTwitter", function(error, results) { console.log(results.content); //results.data should be a JSON object });}


