Javascript Meteor HTTP调用的问题
我是Meteor的新手,在尝试发出HTTP GET请求时遇到困难。我遵循的是一个关于HTTP请求的教程,我基本上遵循它到了T,但当我导航到页面时,似乎什么都没有显示。我添加了Meteor HTTP,但我的client.js文件上的函数似乎没有启动。当我使用浏览器导航到纽约时报时,我可以看到JSON,但在我的页面上什么也看不到 在我的客户端文件夹中,这是my home.html:Javascript Meteor HTTP调用的问题,javascript,http,meteor,Javascript,Http,Meteor,我是Meteor的新手,在尝试发出HTTP GET请求时遇到困难。我遵循的是一个关于HTTP请求的教程,我基本上遵循它到了T,但当我导航到页面时,似乎什么都没有显示。我添加了Meteor HTTP,但我的client.js文件上的函数似乎没有启动。当我使用浏览器导航到纽约时报时,我可以看到JSON,但在我的页面上什么也看不到 在我的客户端文件夹中,这是my home.html: <template name="home"> <div class="page-header">
<template name="home">
<div class="page-header">
<h1>Home</h1>
You are home!
<select class="news">
<option>sports</option>
<option>politics</option>
<option>business</option>
</select>
<h1>news:<small>{{currentnews}}</small></h1>
</div>
</template>
最后是服务器文件夹中的server.js:
Meteor.methods({
'getNews':function(subject){
return Meteor.http.call('GET', 'http://api.nytimes.com/svc/search/v2/articlesearch.json?callback=svc_search_v2_articlesearch&q='+subject+'&begin_date=20150402&end_date=20150402&sort=newest&api-key=[apikeyhere]');
}
})
您确定模板名称正确吗?你的例子对我来说没有多大意义 Template.layout.currentnews看起来有误 您的模板名为home 试着把你的代码放进去
Template.home.rendered = function(){
Meteor.call('getNews',news,function(err, results){
console.log(results.content);
console.log('hello from currentnews function');
Session.set('news', JSON.parse(results.content));
});
};
Template.home.helpers({
currentnews: function()
{
return Session.get('news');
}
});
您可能需要修复封口。对不起,我打错了。我的意思是在服务器文件夹中编写server.js。我刚刚编辑了这个问题以反映这一点。谢谢你的帮助。我使用了错误的模板名称。我对Meteor中文件的组织方式仍然很陌生。
Template.home.rendered = function(){
Meteor.call('getNews',news,function(err, results){
console.log(results.content);
console.log('hello from currentnews function');
Session.set('news', JSON.parse(results.content));
});
};
Template.home.helpers({
currentnews: function()
{
return Session.get('news');
}
});