加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

原型 – 是否有AJAX启动/停止事件全局触发AJAX模态等待消息?

发布时间:2020-12-16 02:54:14 所属栏目:百科 来源:网络整理
导读:在Prototype中,是否有 AJAX启动/停止事件,允许您创建一个脚本,以便在AJAX加载期间全局显示模态等待消息? 就像,使用jQuery我在应用程序布局中使用这个脚本来全局显示任何jQuery AJAX事件的模态等待对话框: script type="text/javascript"$(document).ajaxSt
在Prototype中,是否有 AJAX启动/停止事件,允许您创建一个脚本,以便在AJAX加载期间全局显示模态等待消息?

就像,使用jQuery我在应用程序布局中使用这个脚本来全局显示任何jQuery AJAX事件的模态等待对话框:

<script type="text/javascript">
$(document).ajaxStart(function () {
    $.blockUI({ message: '<h1><img src="../images/busy.gif" /> Just a moment...</h1>' });
});
$(document).ajaxStop(function () {
    $.unblockUI();
});
</script>

谢谢 – 非常感谢?

解决方法

使用Prototype,您可以访问变量Ajax.activeRequestCount( more info here)

This contains,at any time,the amount
of currently active AJAX requests
(those created by Prototype,anyway),
by monitoring their onCreate and
onComplete events

编辑

未经测试但这样的事情应该有效:

Ajax.Responders.register({
  onCreate: showProcessing,onComplete: hideProcessing
});

function showProcessing() {
  if(Ajax.activeRequestCount > 0){
        $('inProgress').show();
    }
}

function hideProcessing () {
  if(Ajax.activeRequestCount <= 0){
      $('inProgress').hide();
  }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读