2017-09-29 4 views
0

テーブルから行を削除しますが、ajaxの成功部分は実行されません。あなたが明示的にcontextを設定しない限り、あなたの成功コールバックの内側ajaxステートメント内でjQueryを使用してテーブル行を削除する

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

答えて

1

thisは、AJAX呼び出しを行うコードでthisと同じにはなりません。

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

私は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(); 
      }); 
     } 
    }); 
}); 
関連する問題