我有一个包围http.get的Meteor方法.我试图将http.get的结果返回到方法的返回中,以便在调用方法时可以使用结果.
我不能让它工作.
这是我的代码:
(在共享文件夹中)
Meteor.methods({
getWeather: function(zip) {
console.log('getting weather');
var credentials = {
client_id: "string",
client_secret: "otherstring"
}
var zipcode = zip;
var weatherUrl = "http://api.aerisapi.com/places/postalcodes/" + zipcode + "?client_id=" + credentials.client_id + "&client_secret=" + credentials.client_secret;
weather = Meteor.http.get(weatherUrl, function (error, result) {
if(error) {
console.log('http get FAILED!');
}
else {
console.log('http get SUCCES');
if (result.statusCode === 200) {
console.log('Status code = 200!');
console.log(result.content);
return result.content;
}
}
});
return weather;
}
});
Run Code Online (Sandbox Code Playgroud)
出于某种原因,即使它们存在并且http调用有效,它也不会返回结果:console.log(result.content); 确实记录了结果.
(客户端文件夹) …