【问题标题】:meteor.call does not call method from meteor.methodmeteor.call 不从meteor.method 调用方法
【发布时间】:2015-02-17 20:30:58
【问题描述】:

我的回调方法有问题。

我在服务器文件夹中的 methods.js 上创建了 在 client/test/mytest 文件夹中有一个 callback.js 文件。

我的 callback.js 包含以下代码

Template.testHello.events({
  "click #testHello": function(e) {
    Meteor.call("testmethod",function(error, id) {
      if (error) {
        Errors.throwError(error.reason);
      }
      return false;
    });

    return false;
  }
});

和methods.js文件代码是

Meteor.methods({
testmethod: function(att) {
    alert("hello testmethod..");
  }
});

但是当我点击按钮“testHello”时,它给了我类似“内部服务器错误 500”的错误。

有人知道吗?

谢谢,

【问题讨论】:

    标签: meteor


    【解决方案1】:

    只有客户端的方法调用没有意义,因为 Meteor 方法旨在在服务器上执行 RMI(远程方法调用)。

    如果您希望您的方法在客户端具有模拟对应项,请将您的 methods.js 移动到 server/methods.jslib/methods.js

    编辑:

    正如@user728291 所暗示的,alert 方法是在 window 对象上定义的,该对象是与浏览器相关的对象,因此只能在客户端环境中使用,您可以使用 console.log 在服务器上打印一些东西。

    【讨论】:

    • 好的,我已将我的 methods.js 移动到 server/ 文件夹,但它仍然给出同样的错误。
    • 我认为您现在遇到了另一个错误,即 alert() 不是服务器上的函数。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-04
    • 2013-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-02
    • 2018-08-29
    相关资源
    最近更新 更多