JSFiddle - React, Tailwind, and code Playground
HTML
dojox.xhrPlugins example to set a default timeout property on all xhr* requests. xhrPlugins is a dojo.AdapterRegistry instance. The signature to register a new plugin is:
<pre>
<em>name</em> // arbitrary string name for the plugin
<em>test function</em> // return true/false to apply or not)
<em>handler<em> // replace or wrap the dojo.xhr function
// that would normally be called)
<em>directReturn</em> // not needed here - you can return a value rather than exec a function
<em>override</em> // apply by default? Sets precedence - true in this case
JavaScript
dojo.require("dojox.io.xhrPlugins");
dojo.ready(function(){
dojox.io.xhrPlugins.register(
"default-timeout",
function(method, args) {
// optionally filter by url/method to selectively apply this plugin
return true;
},
function(method, args, hasBody) {
// augment/replace args and implementation for the request at will
args.timeout = 5000;
// the original dojo.xhr is stored at dojox.io.xhrPlugsin.plainXhr for you
return dojox.io.xhrPlugins.plainXhr.call(dojo, method, args, hasBody);
},
null, true
);
// will error as url doesn't exist, but you get the idea
dojo.xhrGet({ url: "foo.bar" });
});