How can i mimic an ajax call


I should get an authentication from another website to use a java applet. I have two problems, one of them is CORS, I tried to solve it via‘get’…) from server and the other one is await/async. My solutions is always return as undefined.

But couldn’t solve the problem.

I should mimic this
$.ajax("http://********sign.php?request=" + toSign).then(resolve, reject);

and try to solve like this


return function(resolve, reject) {
    await Meteor.promiseCall('setSignaturePromise', toSign).then(resolve, reject);

server.js'get', 'http://********sign.php?request=' + toSign);

How can i solve this problem? Thanks.

You’re mixing “sync-style” async/await with Promise chains. The await ... returns with the result. You can use catch in the event of an error:

try {
  const result = await Meteor.promiseCall('setSignaturePromise', toSign);
  // do something with result
} catch(error) {
  // do something about the error

On the server, your setSignaturePromise method will look something like:

  setSignaturePromise(toSign) {
    try {
      return'get', 'http://********sign.php?request=' + toSign);
    } catch(error) {
      throw new Meteor.Error(...);