javascript - Decrement scalar Perl variable everytime an ajax script is ran -
on page there header notification button shows number of unarchived notifications given perl code:
@notices_posts = system::notice->fetch_all_posts(userid => $user->userid(), visible => 1); @regular_posts = sort { $a->created() cmp $b->created() } grep { !$_->important() } @notices_posts;
and displayed in header:
<b><%= (scalar @regular_posts) %></b>
i have ajax script:
$(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"); }); });
which runs everytime clicks "archive" button on notice. have notice becomes grayed out when perl script archiving run want update scalar number in header displaying number of unarchived notices everytime user archives something. decrement displayed value perchance everytime ajax script ran.
i'd give element id , utilize jquery set number.
<b id="incme"><%= (scalar @regular_posts) %></b> ... $(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"); $('#incme').html(parseint($('#incme').html(), 10)+1) }); });
reference: jquery increment value of <span> tag
javascript ajax perl
No comments:
Post a Comment