如何用Promise解决嵌套ajax调用?
$ionicLoading.show({template: '校验信息中...'});
$http.post('/API/ClientAuthorize/GetUserByOpenID',{OpenID: openId})
.success(function(json){
if(json['ErrCode'] == 0){
$ionicLoading.show({template: '提交订单中...'});
$http.post('/API/ClientBooking/MakeBooking', {
name: json.Data.name,
phone: json.Data.phone,
date: '2017-01-13'
})
.success(function(json){
if(json['ErrCode'] == 0){
$state.go('xxx', {id: json.Data.id});
}
else{
alert(json['errMessage']);
}
})
.error(function(){
$ionicLoading.show({
template:'网络环境欠佳,请稍后重试',
noBackdrop: true,
duration: 1000
});
})
}
else{
$ionicLoading.hide();
alert(json['ErrMessage'])
}
})
.error(function(){
$ionicLoading.show({
template:'网络环境欠佳,请稍后重试',
noBackdrop: true,
duration: 1000
});
})