i am building a notification system for my project,i am more of a php developer what i want to accomplish is that when a user clicks on a notification link eg [3] means there are 3 unread notifications,what i want is that when a user clicks and see these notifications to update my notification table and set seen field to 1 so as a notification link will be [0] and i know this can be achieved through ajax request or any other method if anyone can help will appreciate a lot coz m finalizing my project and run out of time :-) here z my code
<?php if (isset($this->session->userdata['messagecount'])): ?>
<?php if (empty($this->session->userdata['messagecount'])){echo "<button class='btn'></button>";}else{
$count=$this->session->userdata['messagecount'];
echo "<button class='btn btn-info dropdown-toggle notify-btn' data-toggle='dropdown' onclick='updateNotifications()'href='#'>".$count."</button>";
}?>
<?php endif; ?>
<ul class="dropdown-menu">
<div class="notify-wrapper">
<div class="scroll">
<div class="scroll-body">
<ul class="notification-list">
<?php if (isset($this->session->userdata['notification'])): ?>
<?php if (empty($this->session->userdata['notification'])){echo "No Notifications";}else{
$notification=$this->session->userdata['notification'];
echo $notification;
}?>
<?php endif; ?>
</ul>
</div>
</div>
</div>
</ul>
<?php }else{?>
<?php }?>
</li>
Try this dirty code and change as per your requirements:
<div id="notification_counter"><?php echo $note; ?></div>
<div id="notification_container">
<ul>
<li class= "notification_heading" onClick="read_notification_url">one</li>
<li class= "notification_heading" onClick="read_notification_url">two</li>
<li class= "notification_heading" onClick="read_notification_url">three</li>
</ul>
</div>
<script>
$(function() {
$(".notification_heading").click( function(){
var rquest = $.ajax({
type: "POST",
url: "url_to_modify_counter",
});
rquest.done(function( msg ) {
$('#notification_counter').val($('#notification_counter').val()-1);
}
});
});
</script>
be sure to make it safe and data type conversion and all security checks