Flow of logic from client to server and server to client in Meteor

Posted By : Parveen Kumar Yadav | 14-Jul-2016

First on html side you just need to add an id on your button attribute on which call you want to run the functions like:-

You need to bind an event at client side like:-

 Template.channels.events({
                  'click #regsiter': function(event){
			            var user ={};
                        user.name = event.target.name.value;
                        user.email = event.target.email.value;
			            Meteor.call('userRegistration',user,function(error,response){ // calling server side method
				       if(response){
					        //do what you want to do with response
                              		console.log("response");
				       }
				       else{
					     //do what you want in case of errors
					     console.log(err);
				    }
                   	})
});
 

In the above way you can get values of your forms input and pass them into a method name userRegistration that is a method in server side so after processing with server side the response will be render here.

What is going on server side lets have a look :-

 			Meteor.methods({
 				userRegistration: function(user) {
					// do whatever your logic to save the user details in Db than return the response
				}
			})
 

The return response from here is directly go to the client side as above discuss now you have response from server to client side so you just need to render the response to html via using Helper functions of Meteor. 

 

Note:- If you don't know how to render the response via helper function in meteor than please check out my blog written on that topic.

 

Thanks

 

About Author

Author Image
Parveen Kumar Yadav

Parveen is an experienced Java Developer working on Java, J2EE, Spring, Hibernate, Grails ,Node.js,Meteor,Blaze, Neo4j, MongoDB, Wowza Streaming Server,FFMPEG,Video transcoding,Amazon web services, AngularJs, javascript. He likes to learn new technologies

Request for Proposal

Name is required

Comment is required

Sending message..