在道场通用加载图标道场、图标、加载

2023-09-10 18:14:36 作者:小虎牙

我给维护一个应用程序,使一些Ajax调用:

I'm giving maintenance to an application that makes several Ajax calls with:

dojo.xhrPost() and  dojo.xhrGet()

和我想补充一个通用的负荷的图标+消息的系统上的所有通话..降神系统我觉得很难和低维护的loadingFunction调用添加到所有负载:所有的功能 XHR

and I want to add a generic loading "icon + message" to all the calls on the system.. seance the system i find difficult and low maintainable to add the loadingFunction call to all the load:function of all xhr

让我徘徊,如果有一种方法可以侦听器添加到系统中的所有Ajax调用,以便每次被打了一个电话显示加载...

so I wander if there is a way to add a listener to all the ajax calls on the system so everytime is made a call show the loading...

我看,我能做到这一点,在1.7方面,但我工作的应用程序与Dojo的1.6版

I read that I can do that with aspect in 1.7 but the application I'm working on is with the Dojo Version of 1.6

所以,如果你知道一种方式来显示一个通用的消息,所有的Ajax调用..

so if you know a way to show a generic message for all the ajax calls.. .

谢谢意见。

推荐答案

您可以做到这一点通过 道场/话题 ,即 IO管道的主题,这是自道场1.4工作。

You can achieve this via dojo/topic, namely IO Pipeline Topics, which works since Dojo 1.4.

请参阅工作的例子在的jsfiddle: http://jsfiddle.net/phusick/cMHdt/

See working example at jsFiddle: http://jsfiddle.net/phusick/cMHdt/

首先,你必须全局启用IO管道主题,集 ioPublish:真正的 dojoConfig 之一, 数据道场-配置 djConfig (取决于您所使用的)。

First of all you have to globally enable IO Pipeline Topics, set ioPublish: true in one of dojoConfig, data-dojo-config or djConfig (depends on which you use).

然后 dojo.subscribe()来具体议题,如:

dojo.subscribe("/dojo/io/start", function(e) {
    dojo.style(throbberNode, "display", "block");
});

dojo.subscribe("/dojo/io/stop", function(e) {
    dojo.style(throbberNode, "display", "none");
});

可用主题根据Dojo文档是:

Available topics according to Dojo documentation are:

/体育馆/ IO /启动时,有没有突出的IO请求被发送出去,一个新的IO请求启动。没有参数​​传递这一主题。 /体育馆/ IO /发送每当一个新的IO请求,开始发送。它通过dojo.Deferred与话题的请求。 /体育馆/ IO /负载是每当一个IO请求加载成功发送。它传递的响应和dojo.Deferred与话题的请求。 /体育馆/ IO /错误是,每当一个IO请求误发送。它传递了错误的dojo.Deferred与话题的请求。 /体育馆/ IO /完成发送每当一个IO请求已经完成,无论是装载或示数。它传递了错误的dojo.Deferred与话题的请求。 /体育馆/ IO /停止时,所有未完成的IO请求完成后发送。没有参数​​传递这一主题。 /dojo/io/start is sent when there are no outstanding IO requests, and a new IO request is started. No arguments are passed with this topic. /dojo/io/send is sent whenever a new IO request is started. It passes the dojo.Deferred for the request with the topic. /dojo/io/load is sent whenever an IO request has loaded successfully. It passes the response and the dojo.Deferred for the request with the topic. /dojo/io/error is sent whenever an IO request has errored. It passes the error and the dojo.Deferred for the request with the topic. /dojo/io/done is sent whenever an IO request has completed, either by loading or by erroring. It passes the error and the dojo.Deferred for the request with the topic. /dojo/io/stop is sent when all outstanding IO requests have finished. No arguments are passed with this topic.