0

I want to return true or false depending of the result of an ajax jquery call,how I can make it an asynchronous call ,this I get a Promise object in pending state

   function codeExists(code){
    return Promise.resolve($.ajax({
      method: "GET",
      url: "ajax.php",
      data: { op:'codeExists', code: code }
    })
      .done(function( response ) {
        if(response == '1')
            return true;
        else
            return false;
      }));
}
Af_doubts
  • 45
  • 7
  • are you trying to see if the call was successful or not? – FabioEnne Jul 03 '17 at 10:12
  • @FabioEnne ,changed – Af_doubts Jul 03 '17 at 10:17
  • Remove the `Promise.resolve` wrapper, `$.ajax` returns a promise for you. The return in the `done` does nothing as it only returns a value from that function (the done function) and you can't call that code directly. It's nonsensical to have a return there. – freedomn-m Jul 03 '17 at 11:09

0 Answers0