【发布时间】:2012-10-20 06:59:20
【问题描述】:
我有一个表格,其中每一行都有一个删除按钮。实际上我每次都删除该行而不检查ajax调用是否成功。我怎样才能做到这一点,以便只有在 ajax 调用正常时才会删除该行。
这是我在每一行的点击处理程序
$("body").on('click', ".ui-icon-trash" ,function(){
var $closestTr = $(this).closest('tr'); // This will give the closest tr
// If the class element is the child of tr
deleteRowFromDB(oTable, closestTr);
$closestTr.remove() ; // Will delete that
});
这里是我的 ajax 调用
function deleteRowFromDB(oTable, sendallproperty){
var deleteEntryRoute = #{jsRoute @Application.deleteConfigurationEntry() /}
console.log("route is: " + deleteEntryRoute.url)
$.ajax({
url: deleteEntryRoute.url({id: sendallproperty}),
type: deleteEntryRoute.method,
data: 'id=' + sendallproperty
});
【问题讨论】:
-
将删除行的代码放入 ajax 调用的成功处理程序中。
-
你能给我看一个示例代码吗?
-
我愿意,但有一些问题。您的 deleteRowFromDB 函数具有参数 oTable 和 sendallproperty,它们似乎用作字符串。当你调用它时,你传递了两个未定义的变量。