我希望从提供JSON格式的网络服务中获取一些货币价格。
以下是我使用的简单示例代码(hello world) -
if (Meteor.isClient) {
Template.hello.greeting = function () {
return "Welcome to webserve.";
};
Template.hello.events({
'click input' : function () {
// template data, if any, is available in 'this'
if (typeof console !== 'undefined')
console.log("You pressed the button");
Meteor.call('getprice');
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
Meteor.methods({
getprice: function() {
console.log('On the server');
var url = "http://quotes.instaforex.com/get_quotes.php?m=json&q=AUDUSD";
//var url ="http://www.google.com";
HTTP.get(url, function(error, result) {
if(!error) {
console.log(result.content);
}
else console.log(error);
});
}
});
}
当我运行应用程序,然后单击客户端中的按钮时,我在服务器上收到超时消息。 注意网址 - 如果我在浏览器中复制/粘贴它,我会收到正确的json, 跨域策略不适用,因为代码位于服务器端。
有什么想法吗?
答案 0 :(得分:0)
复制到新项目有帮助,无需更改。