With the "old" Dojo one could pass a second argument ioargs
to the load
function of a Xhr request (see Example 6 here). This ioargs
provided (among other things) the timestamp and status code of the request.
But how can I achieve this with the new and "cleaner" (and forward compatible) Dojo?
Unfortunately, I could not find any hints in the current documentation.
The following should be a port of above referenced example to the "new" Dojo. But, ioargs
will be undefined:
require( "dojo/request/xhr", "dojo/dom", "dojo/domReady!",
function(request, dom){
// Look up the node we'll stick the text under.
var targetNode = dom.byId("getLicenseStatus");
// The parameters to pass to xhrGet, the url, how to handle it, and the callbacks.
request.get(
"{{dataUrl}}dojo/LICENSE",
{
handleAs: "text",
preventCache: true
}
).then(
function(data, ioargs){
// FIXME: ioargs is undefined
targetNode.innerHTML = "XHR returned HTTP status: " + ioargs.xhr.status;
},
function(error){
targetNode.innerHTML = "An unexpected error occurred: " + error.response.status + ": " + error.response.text;
}
);
}
);
What do I need to change to have the request's timestamp and status code available in the load function?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…