Counter button with Update

-1

I'm having problems getting a button in javascript to perform an update without giving refresh on the page, at the moment it is not entering the database and is doing refresh hehehe

in index.php

<form>
    <button data-id='$futid' class='botao-olho' style='background-color: red;color:#fff'><i class="far fa-thumbs-up"></i>Sim</button>
</form>
<script type="text/javascript">
    //pega-se o botão desejado e arzena na variável

    $(".botao-olho").on("click", function(){ 
        var $this = $(this); 
        $.ajax({ 
            url: "update_intencao.php", 
            data: {id: $this.data("id")}, 

        }); 
    });
</script> 

Update.php

<?php     

 include("conexao.php"); 

 $id = $_POST['id']       
 $sql3 = "UPDATE fifa19futdados set intencoes = intencoes + 1 where Futbin_ID = $id";

 mysqli_query($conexao,$sql3);   

 ?>

If you do not ask for much, I would also like you to depose the action, he would disappear the button and a message appeared, without refresh.

Thank you!

    
asked by anonymous 28.11.2018 / 19:43

1 answer

0

Without much modification in your code or check the return of the update, an option would be:

<script type="text/javascript">
$(".botao-olho").on("click", function(){ 
    var $this = $(this); 
    $.ajax({ 
        url: "update_intencao.php", 
        data: {id: $this.data("id")}, 
        success: function(response) {
            $this.remove();
        }

    }); 
});

However, it is advisable that you adopt a communication protocol to handle errors such as JSON. So your uodate_intencao.php can return structured responses to javascript.

    
28.11.2018 / 20:23