this is the code in Mini Program. Now getStorage has entered the fail callback
.const ajax = (option="",data=null,type="POST",t=0)=>{
return new Promise((resolve,reject)=>{
wx.getStorage({
key: "openid",
success: (res)=> {
data = data || {openid:res.data}
console.log(data,"C") //data 3
app.util.request({
"url": "entry/wxapp/" + option,
data: data,
method: type,
cachetime: t,
success: (res) => {
console.log(res,"D") //res 4
resolve(res)
},
fail: (res) => {
reject(res)
}
})
},
fail:(res)=>{
wx.login({
success:(res)=>{
console.log(res)
const code =res.code
app.util.request({
"url": "entry/wxapp/open",
data:{
code:code
},
success: (res) => {
console.log("""A") // 1
wx.setStorage({
key: "openid",
data: res.data.openid,
success:(r)=>{
console.log("","B") // 2
ajax(option,data,type,t);
}
})
},
fail: (res) => {
ajax(option, data, type, t);
}
})
}
})
}
})
})
}
const getPra = ()=>ajax("user")
getPra().then(res=>{
console.log(res) //
})
the order of printing is that ABCD, feels that it is successful to re-call ajax after entering the fail callback. Why can"t the following then print something? please explain
.