JSFiddle - React, Tailwind, and code Playground

HTML

<form action="addCustomer_basic.php" method="post"
name="adFrm" id="myform" >
<input name="name" type="text"   
 class="txtfld" id="name"    
 value=">" style="width:250px;"/>
<input name="email" type="text" 
class="txtfld" id="email" value=""  style="width:250px;"/>
<input id="btnn" name="submit" type="submit" value="Submit" />
</form>

JavaScript

var data = {
        json: JSON.stringify({
            msg: 0
        }),
        delay: 1
}

var msg = null;

var echo = function() {    
    return $.ajax({
        type: "POST",
        url: "/echo/json/",
        data: data,
        cache: false,
        success: function(json){
            ajaxFinished = true;
            msg = json.msg;
        }
    });
};

$( "#myform" ).submit(function( event ) {
    echo();
    
    var inter = setInterval(function(){
        console.log("waiting: " + msg);
        if (msg != null){
            clearInterval(inter);
        }
        if (msg == 0){
            alert("Submitting form");
            $( "#myform" ).off();
            $( "#btnn" ).trigger("click"); //submit form
        }
        else if (msg == 1){
            alert("Email already exists");
        }
    }, 200);
    
   return false; //always return false, we'll submit inside the interval
});