http://docs.meteor.com/#meteor_methods
I have tried it in publish.js in my server folder.
I am successfully calling Meteor.apply and attempting the server call from the client. I always get an undefined response.
Calling Meteor.methods
on the server is correct. That will define remote methods that run in the privileged environment and return results to the client. To return a normal result, just call return
from your method function with some JSON value. To signal an error, throw a Meteor.Error
.
On the client, Meteor.apply
always returns undefined
, because the method call is asynchronous. If you want the return value of the method, the last argument to apply
should be a callback, which will be passed two arguments: error
and result
, in the typical async callback style.
Is your server code actually getting called? You can check that by updating the DB in the method and seeing if the client's cache gets the new data, or calling console.log
from inside the method body and looking at the output of the "meteor" process in your terminal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With