5.4.7 The Ajax.Responders object

优质
小牛编辑
130浏览
2023-12-01

继承自Enumerable

这个对象维持一个在Ajax相关事件发生时将被调用的对象的列表。比如,你要设置一个全局钩子来处理Ajax操作异常,那么你就可以使用这个对象。

PropertyTypeKindDescription
respondersArrayinstance被注册到Ajax事件通知的对象列表。
MethodKindArgumentsDescription
register(responderToAdd)instanceresponderToAdd: object with methods that will be called.被传入参数的对象应包含名如Ajax事件的系列方法(如onCreate,onComplete,onException)。通讯事件引发所有被注册的对象的合适名称的函数被调用。
unregister(responderToRemove)instanceresponderToRemove: object to be removed from the list.从列表中移除。
dispatch(callback, request, transport, json)instancecallback: name of the AJAX event being reported, request: the Ajax.Request object responsible for the event, transport: the XMLHttpRequest object that carried (or is carrying) the AJAX call, json: the X-JSON header of the response (if present)遍历被注册的对象列表,找出有由callback参数决定的那个函数的对象。然后向这些函数传递其它的三个参数,如果Ajax响应中包含一个含有JSON内容的X-JSON HTTP头,那么它会被热行并传入json参数。如果事件是onException,那么transport参数会被异常代替,json不会传递。