Meteor.http.call: How do I assign the results of Meteor.http.call to a variable at server side? -


i have following code:

meteor.http.call("post","/abcd/efd",{data:payload}, function (error,result) {     if (error){         //...     } else {          myresult=result     } }); console.log("myresult-->",myresult) //myresult undefined here 

i cannot use session since code in server side.

you calling asynchronous function, why

console.log("myresult-->",myresult) //myresult undefined here 

is called after meteor.http.call has been executed, no matter whether result has been received or not.

since on server side, however, can call synchronous version of http:

import { http } 'meteor/http'  const myresult = http.call("post", "/abcd/efd", {data:payload}); console.log("myresult-->" result) //myresult defined here 

more read on: https://docs.meteor.com/api/http.html#http-call


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -