我正在使用 codeigniter 在数据表上加载数据,数据表上的每一行都有一个链接,单击该链接时数据将发送到其他地方。该特定行中的数据应消失,仅保留未单击的链接。我已经成功地使用 AJAX 做到了这一点,但是成功后我被迫在 jQuery 超时时重新加载页面
示例:
//Table headers here
<tbody class="tablebody">
<?php foreach ($worksheets as $sheets) : ?>
<tr>
<td><?php echo $sheets->filename ?></td>
<td class="bold assign">
<?php echo $sheets->nqcl_number ?>
<?php echo anchor('assign/assing_reviewer/' . $sheets->nqcl_number, 'Assign') ?>
<a id="inline" href="#data">Assign1</a>
<input type="hidden" id="labref_no" value="<?php echo $sheets->nqcl_number; ?>" />
</td>
<td><?php echo $sheets->uploaded_by ?></td>
<td><?php echo $sheets->datetime_uploaded ?></td>
<td></td>
</tr>
<?php endforeach; ?>
</tbody>
我希望在 AJAX 成功时,链接所在的数据表行会从表中动态删除,而无需刷新页面。
$.ajax({
type: "POST",
url: "<?php echo base_url(); ?>assign/sendSamplesFolder/" + labref,
data: data1,
success: function(data) {
var content = $('.tablebody');
$('div.success').slideDown('slow').animate({opacity: 1.0}, 2000).slideUp('slow');
$.fancybox.close();
//Reload the table data dynamically in the mean time i'm refreshing the page
setTimeout(function() {
window.location.href='<?php echo base_url();?>Uploaded_Worksheets';
}, 3000);
return true;
},
error: function(data) {
$('div.error').slideDown('slow').animate({opacity: 1.0}, 5000).slideUp('slow');
$.fancybox.close();
return false;
}
});
我已经尝试过,但它加载了两个相同的页面。有什么解决办法吗?
content.load(url);
最佳答案
您可以使用fnDraw()
强制数据表重新查询数据源。试试这个:
// store a reference to the datatable
var $dataTable = $("#myTable").dataTable({ /* Your settings */ });
// in the AJAX success:
success: function(data) {
$dataTable.fnDraw();
},
阅读 documentation 中的 fnDraw
条目.
关于javascript - 刷新数据表数据而不重新加载整个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13820587/