client method
Meteor.methods({
insertPost: function(data) {
console.log('client')
Posts.insert(data, function(err, ret) {
console.log('client insert end')
});
},
});
server method
Meteor.methods({
insertPost: function(data) {
console.log('server')
Meteor._sleepForMs(200000);
Posts.insert(data, function(err, ret) {
console.log('server insert end')
});
},
});
client submit
'click #save': function(e) {
// data = ....
Meteor.call('insertPost', data, function(error) {
Router.go('/');
});
},
Why does client stuck at form page, instead of instantly going to '/'.
Here is the meteor documentation about it.
Calling methods on the client defines stub functions associated with server methods of the same name. You don't have to define a stub for your method if you don't want to. In that case, method calls are just like remote procedure calls in other systems, and you'll have to wait for the results from the server.
If you do define a stub, when a client invokes a server method it will also run its stub in parallel. On the client, the return value of a stub is ignored. Stubs are run for their side-effects: they are intended to simulate the result of what the server's method will do, but without waiting for the round trip delay. If a stub throws an exception it will be logged to the console.