I want to reload the datatable after I insert the new data in the database. I have written this code of 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>
But it gives me that error in the console.log.
Uncaught TypeError: Cannot read property 'reload' of undefined on that line
$("#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();
}
});
});
.ajax
at least. – Chase Choi