Promise
2018-12-13 本文已影响0人
哈哈我爱你
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style>
</style>
</head>
<body>
</body>
<script src="https://cdn.staticfile.org/jquery/3.3.1/jquery.min.js"></script>
<script>
var promise1 = new Promise((resolve,reject)=>{
$.ajax({
type: "POST",
url: "XXX",
data: {},
dataType: "json",
success: reject,
error:reject
});
}).then(res=>{
// console.log(res,'listBbsUserInfo')
// throw new Error('listBbsUserInfo')
return res
})
var promise2 = new Promise((resolve,reject)=>{
$.ajax({
type: "POST",
url: "XXX",
data: {},
dataType: "json",
success: resolve,
error:reject
});
}).then(res=>{
// console.log(res,'listUserBlockReason')
return res
})
Promise.all([promise1,promise2]).then(res=>{
console.log(res,'all')
}).catch(err=>{
console.log(err,'err')
})
</script>
</html>