Ajax请求解除Twitter引导警报 [英] Ajax request on dismissal of twitter bootstrap alerts

查看:36
本文介绍了Ajax请求解除Twitter引导警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Twitter Bootstrap的警报"功能来显示用户通知,如下所示:

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

<div class="notification alert alert-info">
 <button type="button" class="close" data-dismiss="alert">&times;</button>
 My message goes here
</div>

这些通知将一直保留,直到用户将其关闭为止,因此,当用户单击关闭"按钮时,我想向服务器触发一个ajax查询,指示应永久关闭该通知.

These notifications are persistent until the user dismisses them, so when the user clicks the "close" button I would like to fire off an ajax query to the server indicating that the notification should be permanently dismissed.

我正在使用jQuery的 on()函数,如下所示:

I'm using jQuery's on() function like so:

$(document).on('click', '.notification .close', function (e) {
    alert('hi!');
    console.log(e);
    e.preventDefault();
});

这很好,但是我想知道是否有一种"Bootstrappy"方式来做到这一点?

This works fine, but I'm wondering if there is there a "Bootstrappy" way of doing this?

推荐答案

根据有关警报的Bootstrap文档,我将绑定到对Bootstrap定制的close或close事件.

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);
});

有两个通过API公开的事件:

there are two events exposed via the API:

  1. 关闭-立即触发
  2. 已关闭-在所有动画完成后触发.我选择关闭-这样您就可以立即执行关闭操作,并且如果他们在动画完成之前导航/关闭,它仍将被隐藏.

data属性将使服务器端脚本能够区分警报.标记为:

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>

这篇关于Ajax请求解除Twitter引导警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆