简体   繁体   中英

Meteor server method returns undefined in callback

How can I get my server methods response in client ? When I call a server method and do a console.log on response, it gives me "undefined" on the client, but on the terminal, it returns the value as expected.

My meteor version is Meteor 1.3.2.4

Method on server

Meteor.methods({
    TestMethodOnProd : (arg) => {
        console.log("In Prod ", arg)
        return Meteor.userId()
    }
})

Calling method on client.

Meteor.call("TestMethodOnProd","Some text on prod",(err,res)=> {
    console.log("Err ",err)
    console.log("Res ",res)
})

Console.log on Client (Browser) returns

Err  undefined
Res  undefined

Console.log in the Terminal returns

Err  undefined
Res  <user_id_here>

Try this on the client:

Meteor.call("TestMethodOnProd","Some text on prod",(err,res)=> {
   !err ? console.log(res) : console.log(err);
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM