Still pretty new to these new methods.
Declaring an async ajax request as followed:
async function doAjax(email) {
let result;
try {
result = await jQuery.ajax({
url: ajaxurl,
type: 'POST',
data: {"action": "custome_ajax_email_check", "guestemail": email }
});
return result;
} catch (error) {
console.error(error);
}
}
This is being called within another function dubbed validate()
function validate() {
var email = jQuery("#billingemail").val();
if (isValidEmailAddress(email)) {
doAjax(email).then( (data) => ajaxCallResult(data) )
}
. . . . .
Debugging till now, it does as you expect... into validate()
, onto doAjax()
and here's the last function called (minified):
function ajaxCallResult(data){
data = jQuery.parseJSON(data);
if(!data.result) {
return true;
}
else {
return false;
}
}
But now I need the return (boolean in this case) from ajaxCallResult()
... as a true or false indicates whether a users email exists or not.
But as its chained, I am not sure how to declare it a variable to return the result from.