I am trying to update multiple data through AJAX but I have tried several times, but the data has not changed, please help to fix it in order to run perfectly.
Controllers:
function update_notif() {
$this->My_model->update_multiple();
$this->session->set_flashdata('msg',
'<div class="callout callout-warning">
<h4>Success</h4>
</div>');
}
Models:
function update_multiple() {
$update = $this->input->post('id_pesan');
for ($i=0; $i < count($update) ; $i++) {
$data = array('notif' => 0);
$this->db->where('id', $delete[$i]);
$this->db->update('my_table', $data);
}
}
Views:
<button type="button" id="btn_delete" ></button>
<table class="table table-hover table-striped">
<thead>
<tr>
<td><input id="selecctall" type="checkbox"></td>
<td>No</td>
<td>Name</td>
<td>Telp</td>
</tr>
</thead>
<tbody>
<?php foreach ($show_data as $row) { ?>
<tr>
<td><input type="checkbox" class="select_update" name="select_update[]" value="<?php echo $row->id; ?>"></td>
<td><?php echo $row->no; ?></td>
<td><?php echo $row->nama; ?></td>
<td><?php echo $row->telp; ?></td>
</tr>
</tbody>
<?php } } ?>
</table>
Ajax:
var getVar = [];
$(".select_update:checked").each(function() {
getVar.push($(this).val());
});
$.ajax({
url : url,
type: 'POST',
data: 'id_pesan='+getVar,
dataType: 'json',
success: function(response)
{
if(response){
location.reload();
}
},
error: function (jqXHR, textStatus, errorThrown)
{
alert('Error');
}
});