0

I am creating method which saves customer in database and return response in json format back to calling method. Here is my Code:

    Meteor.methods({
    'Registration': function() {
    name = "Hardik";
    contact = "";
    email = "admin@gmail.com";
    password = "123";
    Meteor.setTimeout(function() {liveDb.db.query('Insert Into Customer (Customer_Name, Customer_Contact, Customer_Password, Customer_Email) values ("'+name+'","'+contact+'","'+password+'","'+email+'")',
        function(error, result){
            if(result!='undefined' && result.affectedRows>0)
            {
                var r = {message : "Customer Added Successfully.", statuscode: "200", customerid : result.insertId};
                return r;
            }
            else
            {
                var r = {message : "Something Went Wrong", statuscode: "400", error : error};
                return r;
            }   
        });},1000);
    }
});

But when I try to fetch returned value in client I am getting nothing Client Side Code:

Meteor.call('Registration', function (error, result) {
        console.log(result);
});
Ubiquitous Developers
  • 3,637
  • 6
  • 33
  • 78

1 Answers1

0

The problem is that you are trying to return response from async callback.

Answer to this question is already give here https://stackoverflow.com/a/12587886/1625793

Community
  • 1
  • 1
Dmitrijs Balcers
  • 157
  • 1
  • 12