Problem Deleting Row in SQL Table with Ajax

Asked

Viewed 35 times

0

I’m with a function, trying to delete a row from my sql table, but nothing has happened.

HTML:

<span class="action"><a href="#" id="<?php echo $id; ?>" class="delete" title="Delete">Sim</a></span>

<script src="js/jquery.js"></script>

<script type="text/javascript">
$(document).ready(function()
{
    $('.delete').click(function()
    {
        if (confirm("Tem certeza que deseja excluir?"))
        {
            var id = $(this).parent().parent().attr('id');
            var data = 'id=' + id ;
            var parent = $(this).parent().parent();

            $.ajax(
            {
                   type: "POST",
                   url: "deletar-aguardando.php",
                   data: data,
                   cache: false,

                   success: function()
                   {
                    parent.fadeOut('slow', function() {$(this).remove();});
                   }
             });
        }
    });

    $('table#delTable tr:odd').css('background',' #FFFFFF');
});
</script>

In the archive deletar-aguardando.php I have:

include_once('conexao.php');

if($_POST['id'])
{
    $id=($_POST['id']);
    $delete = "DELETE FROM clientes WHERE id='$id'";
    mysqli_query($con, $delete);
}

My file conexao.php is working.

1 answer

0


Try to replace where you have var id = $(this).parent().parent().attr('id');

For var id = $(this).attr('id');

  • did not work, continued to do nothing in the document

  • at the beginning of your HTML, what is the value of $id ?

  • when you made this comment you made me find the error, rsrs. At the beginning of html was <?php $id = $dados['idclientes']; ?> where idclientes is the table column name and in the file deletar-aguardando.php I put the name of the column just like id and the right one was idclientes. However thank you, rsrs

  • Any questions, just send direct msg or a comment here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.