![](/img/trans.png)
[英]Meteor method call returns undefined on the client but not on the server
[英]Meteor server method returns undefined in callback
如何在客戶端中獲得服務器方法響應? 當我調用服務器方法並對響應執行console.log時,它在客戶端上給我“未定義”,但在終端上,它按預期返回值。
我的流星版本是Meteor 1.3.2.4
服務器上的方法
Meteor.methods({
TestMethodOnProd : (arg) => {
console.log("In Prod ", arg)
return Meteor.userId()
}
})
客戶端上的調用方法。
Meteor.call("TestMethodOnProd","Some text on prod",(err,res)=> {
console.log("Err ",err)
console.log("Res ",res)
})
客戶端(瀏覽器)上的Console.log返回
Err undefined
Res undefined
終端中的Console.log返回
Err undefined
Res <user_id_here>
在客戶端上嘗試:
Meteor.call("TestMethodOnProd","Some text on prod",(err,res)=> {
!err ? console.log(res) : console.log(err);
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.