AJAX リクエストにコールバックを提供するためにdeferred
andを使用しようとしています。hitch
私は次のコードを使用しています:
//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)
})
})
}
ただし、このコードを実行すると、でundefined method
エラーが発生しthis.resolve(res)
ます。私はthis
(遅延オブジェクトに解決される)両方を印刷しましたres
が、両方とも未定義ではありません。このエラーが発生するのはなぜですか? また、何をしようとしているのですか?