How do I get email_exists to reflect the value of exists outside of the Promise, so I can use it in a conditional?
async function verify_email(email) {
var exists = 0;
await $.ajax({
type: "POST",
url: "/settings/ajax-verify-email",
data: {'email': email},
success: function (response) {
exists = response;
}
});
return exists;
}
var email_exists = 0;
verify_email(email).then(function(exists) {
console.log(exists); // shows 1
email_exists = exists;
}
console.log(email_exists); // shows 0