Per @SallyCJ suggestion to use await
I construed this new function
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);
}
}
Then my validate()
function now just is simply
function validate() {
var email = jQuery("#billingemail").val();
if (isValidEmailAddress(email)) {
doAjax(email).then( (data) => ajaxCallResult(data) )
}
. . . . .
Then lastly
function ajaxCallResult(data){
data = jQuery.parseJSON(data);
. . . . . .
It is working.. very interesting, learning about await
then
, asynchronous
and synchronous
calls, etc