在Dojo中设置xhr请求的默认应用程序范围超时(以使JsonRest调用也受影响) [英] Set default application-wide timeout for xhr requests in Dojo (so that JsonRest calls are affected too)
问题描述
我刚刚发现在Dojo中没有办法为xhr调用设置应用程序范围的超时。在理论上我可以很容易地创建我自己的包装器到xhr并使用它。但是,我正在使用JsonRest商店(目的是只使用商店与应用程序中的数据进行交互)。
I just discovered that in Dojo there is no way to set an application-wide timeout for xhr calls. In theory I could easily create my own wrapper to xhr and use that. However, I am using JsonRest stores (the aim is to only ever use the stores to interact with data in the application).
令人惊讶的是,没有办法设置在Dojo中JsonRest调用的超时。
Amazingly, there is no way to set the timeout for JsonRest calls in Dojo.
http://mail.dojotoolkit.org/pipermail/dojo-interest/2012-April/065594.html
是有一种方法来重载默认的xhr调用,而不必保留我自己的JsonRest的副本?我可以用方面做一些例子吗?想法/评论?
Is there a way to overload the default xhr calls without having to keep my own copy of JsonRest...? Could I do it with aspects for example? Ideas/comments?
推荐答案
最简单的方法可能是一些很好的旧版 Monkey Patching 。
The easiest method is probably some good old Monkey Patching.
var old_xhr = dojo.xhr;
dojo.xhr = function(options) {
var opts = options || {};
opts.timeout = Math.min(opts.timeout || Number.MAX_VALUE, 1000);
return old_xhr(options);
}
这将为$ $的所有用户应用1秒的最大超时时间c $ c> dojo.xhr 方法。使用AMD加载程序的一个无根的dojo有点棘手,每个模块明确要求 dojo / _base / xhr
,但可以通过使用一些先进的别名功能dojo加载器将 dojo / _base / xhr
映射到您自己的模块。
This will apply a maximum timeout of 1 second for all users of the dojo.xhr
method. It's a bit trickier using the AMD loader with a baseless dojo where every module explicitly requires dojo/_base/xhr
, but it can be done by using some of the advanced aliasing capabilities of the dojo loader to map dojo/_base/xhr
to your own module.
这篇关于在Dojo中设置xhr请求的默认应用程序范围超时(以使JsonRest调用也受影响)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!