Skip to content Skip to sidebar Skip to footer

Ajax Request On Dismissal Of Twitter Bootstrap Alerts

I'm using the 'alert' functionality from Twitter Bootstrap to display user notifications, like so:

Solution 2:

According to the Bootstrap docs on alerts, I'd bind to the closed or close event, which are custom to Bootstrap.

$(document).on('close', '.alert', function  () 
{
    var id = $(this).data('some_id'); 
    $.get('closed.php?id='+id);
});

there are two events exposed via the API:

  1. close - which is fired immediately
  2. closed - fires after all animations have completed. I'd opt for close - this way you do it immediately and if they navigate / close before the animation completes, it will still be hidden.

The data attribute is to be able to have the server side script differentiate between the alerts. The markup would be:

<div class="alert" data-some_id='foobar'>
    Close me!
</div>

Post a Comment for "Ajax Request On Dismissal Of Twitter Bootstrap Alerts"