2014-01-14 73 views
1

我希望从提供JSON格式的Web服务获得一些货币价格。简单的流星http呼叫超时

这里是我用简单的例子使用的代码(世界您好) -

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

我试着用一个新的流星项目(用'http'包)使用你的代码,它工作正常。希望你短暂的aud。 – Akshat

+0

复制到Nitrous.io盒子上的新流星项目的工作就像一个魅力,但从我的Windows机器运行它的超时...可能不得不做一些与我的公司防火墙 – tanmay80

回答

0

复制到新项目帮助,无需更改。