在promise中 有其的正确处理 当然也有其独有的错误处理方法
promise的错误处理有两种写法:
1.then方法里放两个函数 第一个是成功的回调 第二个是失败的回调
2.then方法里放成功的回调,继续.catch放失败的回调 jqajax比较特殊,因为他是自己已经封装好的promise对象,catch的写法变成了fail
// 1.一个ajax的错误处理(jqajax的错误处理)
function jq_pro(url,data){
return $.ajax({
url,
data,
dataType:'json'
})
}
jq_pro("a.json").then(res=>{
}).fail(res=>{
console.log(res);
})