Meteor.methods () callback error

I get an error with this code snippet on Meteor.js:

Client side:

      Meteor.call("logUser", function(myvar){
        console.log("le chat client : "+myvar) ;
        Session.set("chatId", myvar);
     });  

Server side:

  Meteor.methods({
      logUser : function(mycallback){
        mycallback("myString");
      }
  });

I really don’t understand why it does not work, the method works well, but the code is interrupted when "mycallback" is called:

"Undefined is not a function"

+4
source share
2 answers

Decision:

Client side:

    Meteor.call("logUser", function(error , result){
      if(error)
          console.log(error.reason);
      else
          console.log(result);

    });

Server side:

 Meteor.methods({
      logUser : function(){
        return "myString";
      }
  });
+5
source

You cannot pass functions as arguments to the Meteor method.

Why is this so?

  • , - ? , - Meteor.call( "logUser", function() { , }); !

  • , Meteor.call JSON, , . , !

, , , Meteor.call, , , , , , , , .

, , " " undefined .

Meteor: (http://docs.meteor.com/#meteor_call)

" ( , ), ."

, - ( ), , , .

+5

All Articles