我正在使用此代码初始化数据表,并在单击删除链接后 - 一切正常,但我正在使用刷新页面,所以我尝试使用 DataTable 函数直接删除行,但根本无法让它工作......这是当前代码(有效的代码,但会刷新整个页面):
<script type="text/javascript">
$(document).ready(function() {
$('#publishers').dataTable( {
"iDisplayLength": 50,
"sPaginationType": "full_numbers",
"bStateSave": true
} );
} );
function DeletePublisher(publisherid) {
jConfirm('Are you sure you want to delete this publisher?', 'Delete publisher', function(r) { if (r)
$.ajax({
type: "GET",
url: 'includes/publishers/delete-publisher.php?publisherid=' + publisherid,
data: '',
success: function(response){
$.jGrowl('Publisher deleted');
window.location.reload();
}
});
});
}
</script>
而在身体...
...A LOT OF UNINTERESTING COLUMNS, AND THE ONE WITH ACTION:
<td class="action-th">
<ul class="button-table-head">
<li><div class="button-head edit-icon"><a href="#" class="sweet-tooltip" data-text-tooltip="Edit" data-style-tooltip="tooltip-mini-slick"><span>Edit</span></a></div></li>
<li><div class="button-head delete-icon"><a href="#" class="sweet-tooltip" data-text-tooltip="Delete" data-style-tooltip="tooltip-mini-slick" onclick="DeletePublisher('<?php echo $publisher_id; ?>')"><span>Delete</span></a></div></li>
</ul>
</td>
我尝试使用此代码,但它不起作用:
function DeletePublisher(publisherid) {
jConfirm('Are you sure you want to delete this publisher?', 'Delete publisher',function(r) { if (r)
$('#publishers tbody').on( 'click', 'tr', function () {
var tr = this;
$.ajax({
type: "POST", //or GET
url: 'includes/publishers/delete-publisher.php?publisherid=' + publisherid,
data: '',
success: function(response){
t.fnDeleteRow( tr );
$.jGrowl('Publisher deleted');
}
} );
});
});
}
任何想法为什么 - 我对 JS、JQuery 完全是菜鸟......