0

I want to delete a row from the table, but the success part of ajax does not execute.

function fn_delete() {
    $("a.delete").click(function () {
        idProduct = $(this).parents("tr").find("td").eq(1).html();
        $.ajax({
            type: "POST",
            url: "DeleteProduct",
            data: { idProduct },
            success: function () {
                $(this).parents("tr").fadeOut("normal", function () {
                $(this).remove();
            }
        });
    });
};
0

2 Answers 2

1

this inside your success callback will not be the same as this in the code that makes the ajax call, unless you explicitly set the context:

$.ajax({
  context: this,
  data: ...
});
Sign up to request clarification or add additional context in comments.

Comments

0

I don't think this is giving the value that you're expecting.

Try this:

function fn_delete() {
$("a.delete").click(function () {
    idProduct = $(this).parents("tr").find("td").eq(1).html();
    var myRow = $(this).parents("tr");
    $.ajax({
        type: "POST",
        url: "DeleteProduct",
        data: { idProduct },
        success: function () {
                $(this).parents("tr").fadeOut("normal", function () {
                myRow.remove();
            });
        }
    });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.