Row is not deleted withing post request

Row is not deleted withing post request

emads3emads3 Posts: 2Questions: 1Answers: 0
edited May 2019 in Free community support

I have this block of code that works properly to delete a row from the table when I click the selected <td>

$('#students-table tbody').on('click', 'i.icon-delete', function () {
        table.row($(this).parents('tr')).remove().draw();
 });

but when I embed this line into $.post.done it doesn't work at all

    $('#students-table tbody').on('click', 'i.icon-delete', function () {
        var student_id = $(this).attr('student_id');
        $.post("backend.php", {"action": "deleteStudent", "student_id": student_id}).done(function (response) {
            response = JSON.parse(response);
            if (response.deleted == "1") {
                console.log("A");
                table.row($(this).parents('tr')).remove().draw();
                console.log("B");
            }
        }); // post
    });

however the condition response.deleted == "1" evaluates to True and console.log("A"); and console.log("B"); also works properly
So why the row deletion line doesn't work when it's inside the done function of the $.post

This discussion has been closed.