【发布时间】:2015-08-21 02:45:10
【问题描述】:
我有多个ajax请求一起工作,每个请求都基于前一个请求的结果,如果前一个请求返回false,则链应该停止。
这里有一些代码
//here is 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 {
// i wanna stop the promise chain here, how to do that?
}
}
【问题讨论】:
标签: javascript ajax ember.js promise