Hello I am just learning codeigniter, here I am displaying a database and there are several rows. I made a delete function with ajax, it worked, but it had to be reloaded, how so that when I click delete, the data is deleted and it doesn't have to be refreshed.
<tbody id="tbody">
<?php
$no = 1;
foreach ($temporary as $m) { ?>
<tr>
<input type="hidden" class="form-control" name="id_service" value="<?php echo $m->id_service ?>">
<input type="hidden" class="form-control" name="id_cs" value="<?php echo $m->id_cs ?>">
<input type="hidden" class="form-control" name="jenis" value="<?php echo $m->jenis ?>">
<td>
<input type="hidden" class="form-control" name="id_tmp" value="<?php echo $m->id_tmp ?>">
<input type="text" class="form-control" name="" value="<?php echo $m->tracking_number ?>">
</td>
<td>
<button type="button" class="btn btn-danger" onclick="deletes(<?php echo $m->id_tmp;?>)">Delete</button>
</td>
</tr>
<?php } ?>
</tbody>
ajax
function deletes(id){
if (confirm("Are you sure?")) {
$.ajax({
url: '<?php echo base_url();?>backend/inbound/del',
type: 'post',
data: {id_tmp:id},
success: function () {
alert('ok');
},
error: function () {
alert('gagal');
}
});
} else {
alert(id + " not deleted");
}
}