【发布时间】:2019-09-07 06:04:40
【问题描述】:
我想在数据库中插入新数据后重新加载数据表。我已经编写了这段 HTML 代码。
<table class="table table-striped table-bordered bootstrap-datatable datatable" id="Slider_table">
<thead>
<tr>
<th>Title</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<?php foreach($items as $row){?>
<tr>
<td><?=$row->item_title;?></td>
<td class="center"><?=$row->item_price;?></td>
</tr>
</tbody>
但它在 console.log 中给了我这个错误。
未捕获的类型错误:无法读取未定义的属性“重新加载” 在那条线上
$("#Slider_table").DataTable().ajax.reload();
$('#add_items').on('click', function(e){
e.preventDefault();
var formData = new FormData($("#form1")[0]); //It automatically collects all fields from form
$.ajax({
url: "<?= base_url(); ?>Items/add_items",
type: "post",
data: formData,
async: false,
cache: false,
contentType: false,
processData: false,
success: function(output) {
$("#Slider_table").DataTable().ajax.reload();
}
});
});
【问题讨论】:
-
1.10.0版本提供reload,你用的是什么版本?
-
'reload' of undefined 表示无法重新加载。至少
.ajax有问题。 -
@Deepak 我正在使用最新版本