'Ajax checking unique email address

Trying to check if email id already exists , here the query is working fine and ajax is working fine but i am unable to submit the form.

Here I am using $( '#form1' ).submit(); to submit the form but still it shows no error and the form is not getting submitted

<form method="post" id="form1" action="practice2.php" class="form-horizontal">
    user id:<input type='text' name='user_id'/>
    email id:<input type='email' id="email" name='email'/>
    password:<input type='password' id="pass" name='pass'/>
    <div id="res" style=" color:red;"></div>
    <input type='button' name='submit' id="btn" value='register'/>
</form>


<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.0/js/bootstrap.min.js" integrity="sha384-7aThvCh9TypR7fIc2HV4O/nFMVCBwyIUKL8XCtKE+8xgCgl/PQGuFsvShjr74PBp" crossorigin="anonymous"></script> 
<script type="text/javascript">
    $(document).ready(function(){
        $('#btn').on('click',function(){
            var email=$('#email').val();
            if(!email==""){
            $.ajax({
                type:'POST',
                url:'practice2.php?action=check',
                data:'email='+email,
                success:function(data){
                    if(data=="true"){
                        alert(data);
                        $( '#form1' ).submit();
                    }else{
                        $('#res').html(data);
                        return false;
                    }
                }
            });
            }
        });
    });
</script>

function

function select1($mail){
    $sth = $this->dbh->prepare("SELECT * FROM `user_detail` WHERE email_id= :email");
    $sth->bindParam(':email', $mail);
    $sth->execute();
    $result=$sth->fetchAll();
    return $result;
}


Solution 1:[1]

Can you try like this?

$('#btn').on('click',function(){
            var email=$('#email').val();
            if(!email==""){

            MyForm = $('#form1');

            $.ajax({
                type:'POST',
                url:'practice2.php?action=check',
                data:'email='+email,
                success:function(data){
                    if(data=="true"){
                        alert(data);
                        MyForm.submit();
                    }else{
                        $('#res').html(data);
                        return false;
                    }
                }
            });
            }
        });

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Carlos Alves Jorge