php - 如何使用ajax jquery删除数据表的行

标签 php jquery mysql ajax datatables

我想在ajax调用后删除表中的行。这是我的代码:

function getResultsMsr(action, msrDel) {
if(action == 'search') {
$('#example').dataTable( {
"processing": true,
"serverSide": true,
"ajax": "testing_ajax.php",
"columnDefs": [ 
 {   
 "aTargets":[7],  // this your column of action
 "mData": null, 
 "mRender": function(data, type, full){
 var rowId= full[6];
return '<td id="row'+msrDel+'"><a href="javascript: void(0);"  onclick="removeRow('+rowId+');" >Delete</a>
  }
  }
 ]
 } );

这是我尝试删除行的删除函数:

function removeRow(msrDel){
var parent = $(this).parent().parent();
$.ajax({
url: 'getResult.php',
type: 'POST',
data: "id="+msrDel
}).done(function(result_data){
parent.fadeOut('slow', function() {$(this).remove();});

});
return false;
}

最佳答案

函数removeRow(msrDel){

            var oTable = $('#example').dataTable();
            var parent = $(this).parent().parent();
            $.ajax({
                url: 'getResult.php',
                type: 'POST',
                data: {
                        formName:'afscpMsr',
                        action:'delete',
                        delmsr: msrDel
                    }
                }).done(function(result_data){
                //  parent.fadeOut('slow', function() {$(this).remove();});
                    oTable.fnDeleteRow( $('#example tbody tr:eq(0)')[0] );
                });

            return false;
            }

关于php - 如何使用ajax jquery删除数据表的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25265198/

相关文章:

php - Firebase 如何发送主题通知

PHP ob_flush();在 IE10 中不起作用

php - 需要一些帮助来为多级 ListView 编写 json。 ^^

javascript - 如何一次验证文本框或浏览按钮?

sql - 为什么这个 mysql 查询会给我垃圾结果?

php - PHP 中的广告管理系统?

javascript - $.inArray 在 IE7 中

jquery - 手机快速点击-防止鬼焦

php - SQL 注入(inject) - 这(oneliner)安全吗?

java - 将位置详细信息传递给 mysql 存储过程