new Promise((resolve,reject)=>{
var timeOut = Math.random() * 2;
setTimeout(()=>{//模拟异步网络请求
if (timeOut < 1) {
resolve('200 OK');
}
else {
reject('404 not found');
}
})
}).then((success)=>{
console.log('成功');
}).catch((fail)=>{
console.log('失败')
})