I'm migrating to jQuery 1.8 and changing my ajax result handlers from success:
and error:
to done()
and fail()
.
However, inside my done()
handlers I start getting errors like
this.each is not a function
although the ajax call contains the context:
parameter as before. Somehow the this
context has vanished.
This is the calling code:
function vzload(args) {
return $.ajax(args).then(function(json) {
if (json.exception) {
var e = new Exception(json.exception.type, args.url + ':<br/><br/>' + json.exception.message);
vz.wui.dialogs.exception(e);
return $.Deferred().reject();
}
return $.Deferred().resolve(json);
});
}
And this is when the error occurs:
var deferred = vz.load({
controller: 'capabilities',
context: someobject
}).done(function(json) {
this.each(...)
});
I've tried changing the resolution to:
return $.Deferred().resolveWith(this, json);
and now the error is
TypeError: json is undefined
What is the correct way to modify the ajax result Deferred when using context objects?