Ajax.Responders

A repository of global listeners notified about every step of Prototype-based Ajax requests
有时候,你需要提供所有的Ajax操作发生页面上通过的Ajax.Request,Ajax.Updater的或Ajax.PeriodicalUpdater通用行为。
例如,您可能希望自动显示指标正在进行时,一个Ajax请求,并隐藏它时都不是。你可能要分解出的异常处理以及在登录页面上自定义时尚的某处。有无数的可能性。
为了实现这一目标, prototype提供Ajax.Responders,它可以让你注册(并且,如果您愿意,后来注销)的反应,这是具有特别的命名方法的对象。这些名字来自一组对应于不同时间点(或成果)的一个Ajax请求的生命周期一般回调。
例如,原型自动注册,保持一个漂亮的变量:Ajax.activeRequestCount一个响应。这意味着,在特定的时间,目前活跃的Ajax请求的数量 - 通过监测他们的onCreate的onComplete事件。此代码是相当简单:
Ajax.Responders.register({   onCreate: function() {     Ajax.activeRequestCount++;   },   onComplete: function() {     Ajax.activeRequestCount--;   } });
Responder callbacks

The callbacks for responders are similar to the callbacks described in the Ajax, but take a different signature. They're invoked with three parameters: the requester object (i.e., the corresponding "instance" of Ajax.Request), the XMLHttpRequest object, and the result of evaluating the X-JSON response header, if any (can be null). They also execute in the context of the responder, bound to the this reference.

  • onCreate: Triggered whenever a requester object from the Ajax namespace is created, after its parameters are adjusted and before its XHR connection is opened. This takes two arguments: the requester object and the underlying XHR object.
  • onUninitialized (Not guaranteed): Invoked just after the XHR object is created.
  • onLoading (Not guaranteed): Triggered when the underlying XHR object is being setup, and its connection opened.
  • onLoaded (Not guaranteed): Triggered once the underlying XHR object is setup, the connection is open, and it is ready to send its actual request.
  • onInteractive (Not guaranteed): Triggered whenever the requester receives a part of the response (but not the final part), should it be sent in several packets.
  • onException: Triggered whenever an XHR error arises. Has a custom signature: the first argument is the requester (i.e. an Ajax.Request instance), and the second is the exception object.
  • onComplete: Triggered at the very end of a request's life-cycle, after the request completes, status-specific callbacks are called, and possible automatic behaviors are processed. Guaranteed to run regardless of what happened during the request.



转载于:https://my.oschina.net/u/617021/blog/71467

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值