Managing multiple ajax requests that are dependent on each other can be tricky, especially when you need to stop the chain if one of the requests returns false.
Check out this sample code snippet below:
// Implementing a promise chain
return this.getBand(id)
.then(this.getAlbum)
.then(this.getSong);
// Ajax request for getBand
function getBand(id) {
return Ember.$.ajax({
data: { id: id },
url: urls.bandUrl,
}).then(function(result) {
return result;
});
};
// Ajax request for getAlbum
function getAlbum(result) {
if (result.pass) {
var bandName = result.name;
return Ember.$.ajax({
//...
})
} else {
// How can we effectively stop the promise chain here?
}
}