My webpage features a header with a notification button that indicates the count of unarchived notifications using this Perl code snippet:
@notices_posts = System::Notice->fetch_all_posts(userid => $user->userid(), visible => 1);
@regular_posts = sort { $a->created() cmp $b->created() } grep { !$_->important() } @notices_posts;
This count is displayed in the header as follows:
<b><%= (scalar @regular_posts) %></b>
An ajax script is implemented on the page:
$(document).on('click', '.archive-button', function(){
var notice_id = $(this).data('notice_id');
var archiveaddress = '/user/notices/archivenotice/' + notice_id;
var archived_notice = 'tr.notification-' + notice_id;
$.post(archiveaddress, {notice_id: notice_id}).done(function(){
$(archived_notice).css("background" , "#F2F2F2");
});
});
This script executes every time a user clicks the "archive" button on a notification. Currently, when the Perl script for archiving runs successfully, the notification turns gray. However, I also want it to update the displayed count of unarchived notifications every time a user archives an item. Ideally, this would involve decrementing the displayed value each time the ajax script is executed.