How to enable a button after validation?

0

I need the button to be enabled when the email does not exist in the database. See that validation if the email exists already works, I need the implementation that enables the button if the email does not exist.

JavaScript

<script type="text/javascript">

$(document).ready(function () {

    $('#email').blur(function() {
        $th = $(this);
          $.ajax({
            url: 'plano.php',
            type: 'POST',
            data: {email: $th.val()},
            beforeSend: function(){
                $("#resultados").html("Carregando...");
            },
            success: function(data){
                $("#resultados").html(data);
            },
            error: function(){
                $("#resultados").html("Ouve um erro ao enviar sua URL");
            }
         });//ajax       
    });
});

</script>

HTML

<div id="resultados"></div>
<button id="registrar" disabled="disabled" type="submit">CONTRATAR AGORA!</button>

plano.php

$email = $_POST['email'];
    #Conecta banco de dados 
    $sql = mysqli_query($con, "SELECT email FROM conta WHERE email = '$email' ORDER BY EMAIL ASC LIMIT 1");

    while($sqlregistro=mysqli_fetch_array($sql))
{
    $emailbanco = $sqlregistro['email'];
}

    echo $emailbanco;
    echo "<br>";

    if(isset($email ) && $emailbanco === $email ){
        echo "Este email existe no banco";
    }else{
        echo "Email digitado " .$emailbanco. " Nao existe no banco "; 
    }
    
asked by anonymous 10.08.2018 / 04:24

1 answer

0
...

success: function(data){
    $("#resultados").html(data);
    if(data.search("Nao existe") != -1)
        $("#registrar" ).prop( "disabled", false );
},

...
    
10.08.2018 / 04:42