這是我的第一個流星計劃,我正在嘗試向Github發起http呼叫。我面臨的是這樣的一個錯誤:MeteorJs - http呼叫中的錯誤
Exception in delivering result of invoking 'getUserInfo': ["click button"]/<@http://localhost:3000/helloMeteor.js?823f404b37c246a7d23ae50a10c37969e426b2b8:18:17 Meteor.bindEnvironment/<@http://localhost:3000/packages/meteor.js?43b7958c1598803e94014f27f5f622b0bddc0aaf:983:17 [email protected]http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:3860:7 [email protected]http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:3880:5 [email protected]http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:4964:7 Connection/[email protected]http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:3725:7 ._launchConnection/self.socket.onmessage/<@http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:2717:11 [email protected]http://localhost:3000/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:156:7 ._launchConnection/[email protected]http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:2716:9 SockJShttp://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:156:9 SockJShttp://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:1141:5 SockJShttp://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:1199:13 SockJShttp://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:1346:9
這裏是我的代碼:
if (Meteor.isClient) {
// counter starts at 0
Session.setDefault('counter', 0);
Template.hello.helpers({
counter: function() {
return Session.get('counter');
}
});
//This is how you bind event handlers
//Format: eventtype selector
Template.hello.events({
'click button': function() {
// increment the counter when button is clicked
Session.set('counter', Session.get('counter') + 1);
Meteor.call('getUserInfo', 'rutwick', function(err, res) {
console.log(result);
});
}
});
}
if (Meteor.isServer) {
//Meteor.startup(function() {
// code to run on server at startup
Meteor.methods({
getUserInfo: function(userN) {
var github = new GitHub({
version: "3.0.0", // required
timeout: 5000 // optional
});
var result = github.user.getFollowingFromUser({
user: userN
});
return result;
}
});
//});
}
我使用Github的API JavaScript包裝。即使我嘗試使用簡單的HTTP進行通話,我仍然會遇到錯誤。
究竟需要做些什麼來解決這個問題?
更新 這裏是服務器日誌:
Exception while invoking method 'getUserInfo' ReferenceError: GitHub is not defined I20150429-19:22:53.064(5.5)? at [object Object].Meteor.methods.getUserInfo (app/helloMeteor.js:29:34) I20150429-19:22:53.064(5.5)? at maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1617:1) I20150429-19:22:53.064(5.5)? at packages/ddp/livedata_server.js:648:1 I20150429-19:22:53.064(5.5)? at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1) I20150429-19:22:53.064(5.5)? at packages/ddp/livedata_server.js:647:1 I20150429-19:22:53.064(5.5)? at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1) I20150429-19:22:53.064(5.5)? at [object Object]._.extend.protocol_handlers.method (packages/ddp/livedata_server.js:646:1) I20150429-19:22:53.064(5.5)? at packages/ddp/livedata_server.js:546:1
我們可以有Chrome控制檯輸出(它更好),如果它適用,服務器日誌也是? – SylvainB
啊哈,服務器日誌。我不知道有一個服務器日誌。我發佈的輸出來自FireBug的控制檯。用服務器日誌更新我的問題。 –
不用擔心:)只顯示服務器日誌,如果它適用。但我至少不能強調使用Chrome *至少*來查看控制檯日誌,其他控制檯至少只是廢話......對於流星來說。 – SylvainB