I'm attempted to use deferred
and hitch
in order to provide a callback for my AJAX request. I'm using the following code:
//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)
})
})
}
However, when I run this code I get an undefined method
error on this.resolve(res)
. I've printed both this
(which resolves to the deferred object) and res
and both are not undefined. Why am I getting this error and how to achieve what I'm attempting to do?