0
我试图使用deferred
和hitch
为了提供我的AJAX请求的回调。我使用下面的代码:使用搭载/推迟xhrGet请求
//Code is executed from this function
function getContent(){
var def = new dojo.Deferred();
def.then(function(res){
console.lod("DONE");
console.log(res);
},
function(err){
console.log("There was a problem...");
});
this.GET("path", def);
}
//Then GET is called to perform the AJAX request...
function GET(path, def){
dojo.xhrGet({
url : path,
load : dojo.hitch(def,function(res){
this.resolve(res);
}),
error : dojo.hitch(def, function(err){
this.reject(err)
})
})
}
然而,当我运行此代码我得到this.resolve(res)
的undefined method
错误。我已经打印了this
(解析为延迟对象)和res
,两者都未定义。为什么我得到这个错误以及如何实现我正在尝试做的事情?