I am working on adding a notification feature and need to run an ajax query through the controller when a button is clicked.
Here's the script I'm using:
$('#noti_Button').click(function (e) {
e.preventDefault();
$.ajax({
url: '<?php echo site_url("profile/read_notif")?>'
});
});
The Controller:
public function read_notif(){
$this->profile_model->read_notifs($data['id']);
return;
}
And the Model:
function read_notifs($id)
{
$read = array(
'read' => '1'
);
$this->db->where('recipient', $id);
$this->db->update('tbl_notifications', $read);
return;
}
After trying this method, I noticed that the database wasn't being updated as expected. In my HTML, it's just a simple button.