【问题标题】:$meteor.call Callback not invoked$meteor.call 未调用回调
【发布时间】:2015-12-21 12:49:02
【问题描述】:

我是 Meteor 的新手,并且有一个 $meteor.call,尽管我在服务器节点检查器中看到 Meteor.method 的返回值,但从未调用过回调。

客户

$meteor.call('login', { url: creds.url, username: creds.user, password: creds.password }, function (err, response) {
  if (err) {
    console.log('login failed');
  } else {
    console.log('login succeeded: ' + response);
    Session.set('ticket', response);
  }
});

服务器

login: function (data) {
  this.unblock();

  var loginSync = Meteor.makeAsync(HTTP.post); // using workaround for wrapAsync issue #2774
  var postResults = loginSync(url + '/ticket', options);
  console.log('return, status: ' + postResults.data.statusCode + ', ' + postResults.data.content);
  return postResults;

【问题讨论】:

    标签: meteor


    【解决方案1】:

    Meteor.call 开头没有 $。

    来自 Meteor 的文档:

    Meteor.call(name, [arg1, arg2...], [asyncCallback])
    

    所以你的电话应该看起来更像:

    Meteor.call('methodName', var1, var2, function(error, result){});
    

    另外,您确定您将数据正确传递到服务器端吗?如果还有更多,我看不到您的变量/其余代码。

    【讨论】:

    • $ 是问题所在。不知道我在哪里捡到的。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2015-07-02
    • 1970-01-01
    • 1970-01-01
    • 2013-09-09
    • 1970-01-01
    • 2018-05-01
    相关资源
    最近更新 更多