微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐