I'm doing an ajax call that can return {status: ok} or {status: error} along with other data.
I'd like to do a .then(doneFilter) that would check the status member and then modify things such that the Deferred now will resolve only if the status was ok.
I'm not sure of the syntax for that. Could someone write me an example?
I think that you want to modify the ajax deferred itself to trigger different callbacks based upon the return state. You can't because
Promiseobjects can be resolved only once. Look at this example:http://jsfiddle.net/ExplosionPIlls/QreYY/
The chain of events would be calling
.resolve, and then the.thencallback..thencalls.reject. However, if you run this you will see that the state after the.rejectcall is still "resolved," and the.donecallback gets triggered.That is to say if your ajax request succeeds it will already be set to the
.resolvedstate and you can't undo that.Instead, you can do something like this, which I think is simpler anyway: