Is there a way to cancel a deferred callback queue in progress? I have an arbitrary amount of ajax calls. I'd like to stop further ajax requests when data of success returns specific marker:
this.oDeferred=$.Deferred();
this.oChain=this.oDeferred;
for(var i=0; i<this.aKey.length; i++) {
(function(iKey,self) {
self.oChain=self.oChain.then(function(){
return $.ajax({
url:self.aUrl[iKey],
type:'post',
data:{'ajax':true},
dataType:'json',
success:function(data) {
if(data.bCancel==true) {
//stop deferred object here!
}
}
});
})
}(this.aKey[i],this))
}
this.oDeferred.done(function() {
console.log('done')
});
this.oDeferred.resolve()
By the way - the function done() is fired autonomous after all ajax requests are made. How to execute a function after all ajax requests are done?
Thank you in advance!