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
,兩者都未定義。爲什麼我得到這個錯誤以及如何實現我正在嘗試做的事情?