小程序request偶尔请求失败,一直在pending直到超时,网络以及服务器都没有异常,一般过一分钟才会恢复正常,下面是封装的request方法,试过header中加’cache-control’: 'no-cache’也没有解决
function apiRequest(url, method, data, success, fail) {
wx.request({
url: ‘xxxxx’ + url,
method: method,
dataType: ‘JSON’,
data: data,
header: {
‘Authorization’: 'bearer ’ + wx.getStorageSync(‘token’),
},
success: function (res) {
if (res.statusCode == 429) {
wx.showModal({
title: ‘错误’,
content: ‘访问过于频繁,请一分钟后再试’,
showCancel: false
})
} else if (res.statusCode == 401){
wx.redirectTo({
url: ‘/pages/back/login/login’,
})
} else {
success(res);
}
},
fail: function (res) {
fail(res);
wx.showToast({
icon:‘none’,
title: ‘请求超时,请稍后再试’,
duration: 2000
})
}
});
}