Javascript 在ajax语句中使用jQuery删除表行
我想从表中删除一行,但ajax的成功部分不会执行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: {
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();
});
}
});
});