【发布时间】:2012-08-28 07:36:53
【问题描述】:
对于“旧”Dojo,可以将第二个参数 ioargs 传递给 Xhr 请求 (see Example 6 here) 的 load 函数。这个ioargs 提供(除其他外)请求的时间戳和状态代码。
但是如何使用新的“更干净”(并且向前兼容)Dojo 来实现这一点?
不幸的是,我在current documentation 中找不到任何提示。
以下应该是上述引用示例到“新”Dojo 的移植。但是,ioargs 将是未定义的:
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;
}
);
}
);
我需要更改哪些内容才能使请求的时间戳和状态代码在加载函数中可用?
【问题讨论】:
-
request.get() 产生的 deferred 里面是否隐藏了信息?
-
request.get()产生(正如@Kniganapolke 也指出)一个promise对象。除了一些函数定义和原型构造函数之外,我找不到任何数据。
标签: javascript dojo xmlhttprequest