小程序内部定时器每1秒调用wx.request向服务端上报一次数据, 退出微信到手机主屏幕并息屏30秒,在打开微信,wx.request无响应
Page({
data: {
motto: 'Hello World',
userInfo: {},
hasUserInfo: false,
beacons: "",
canIUse: wx.canIUse('button.open-type.getUserInfo')
},
onLoad: function () {
__setTimeout();
}
});
function __setTimeout(){
__upload();
clearTimeout();
setTimeout(function(){
__setTimeout();
}, 1000);
}
function __upload(){
wx.request({
url: 'https://www.xxx.com/test/report',
data: {"K":"key","V":"value"},
method:"POST",
success(res) {
console.log(res);
},
fail:function(res1){
console.log(res1);
},
complete:function(res2){
console.log(res2);
}
});
}
onLoad: function () { __setTimeout(); } onLoad换成onShow试试
onShow:function(){
console.log("onShow");
setInterval(function () {
__upload();
}, 1000);
},
onHide:function(){
clearInterval();
}