ajax成功完成时未删除数据id



当我点击成功删除数据的按钮时,我正试图使用CI中的jQuery ajax功能从数据库中删除数据,但当ajax请求完成时,元素不会被删除。

这是HTML代码:

    <td>
        <a href="javascript:void(0)" class="btn btn-danger del_comment" data-id="<?php echo $report->video_comment_id; ?>" data-action="<?php echo site_url('admin/delete_comment') ?>">
            Delted Comment
        </a>
    </td>

这是我的jQuery代码

$('.del_comment').click(function(){
    var comment_report = $(this).data('id');
             $.ajax({
                    url: $(this).data('action'),
                    type: 'POST',
                    data: {
                        comment_report:comment_report
                    },
                    success:function(data){
                        if (true)
                         {
                            $("a[data-id='" + comment_report + "']").find('td').remove();
                         } 
                         else{
                         };
                    },
                    error:function(){
                        alert('somthing worong..')
                    }
            });//ajax ends here                     
});

我不会给你控制器和模型,因为所有的东西都能正常工作。

我想在ajax时删除<td>,我该怎么做?

使用$(this).closest('tr').remove();

https://jsfiddle.net/m42bavqj/

$("a[data-id='" + comment_report + "']").find('td').remove()

以上是在应该查找父TD的情况下查找子TD。

$("a[data-id='" + comment_report + "']").parent('td').remove()

最新更新