Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在ajax语句中使用jQuery删除表行_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript 在ajax语句中使用jQuery删除表行

Javascript 在ajax语句中使用jQuery删除表行,javascript,jquery,ajax,Javascript,Jquery,Ajax,我想从表中删除一行,但ajax的成功部分不会执行 function fn_delete() { $("a.delete").click(function () { idProduct = $(this).parents("tr").find("td").eq(1).html(); $.ajax({ type: "POST", url: "DeleteProduct", data: {

我想从表中删除一行,但ajax的成功部分不会执行

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();
            }
        });
    });
};

成功回调中的
与进行ajax调用的代码中的
不同,除非您明确设置
上下文

$.ajax({
  context: this,
  data: ...
});

我不认为
这个
提供了您期望的价值

试试这个:

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();
            });
        }
    });
});