原型 - 是否有 AJAX 启动/停止事件来全局触发 AJAX 模式等待消息? [英] Prototype - Are there AJAX start/stop events to global trigger an AJAX modal wait message?

查看:35
本文介绍了原型 - 是否有 AJAX 启动/停止事件来全局触发 AJAX 模式等待消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Prototype 中,是否有 AJAX 启动/停止事件允许您创建一个脚本,以便在 AJAX 加载期间全局显示模式等待消息?

In Prototype, are there AJAX start/stop events that would allow you to create one script for globally displaying a modal wait message during AJAX loads?

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

Like, with jQuery I'm using this one script in the application layout to globally display a modal wait dialog for any jQuery AJAX events:

<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 (更多信息在这里)

With Prototype you have access to a variable Ajax.activeRequestCount (more info here)

这在任何时候都包含金额当前活动的 AJAX 请求数(无论如何,那些由 Prototype 创建的),通过监控他们的 onCreate 和onComplete 事件

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

编辑

未经测试,但应该可以:

Untested but something like this should work:

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

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

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

这篇关于原型 - 是否有 AJAX 启动/停止事件来全局触发 AJAX 模式等待消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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