Skip to content

Instantly share code, notes, and snippets.

@cheenwe
Created April 20, 2017 05:40
Show Gist options
  • Save cheenwe/2da05edee35c9dd50a2b41bc2208a38d to your computer and use it in GitHub Desktop.
Save cheenwe/2da05edee35c9dd50a2b41bc2208a38d to your computer and use it in GitHub Desktop.
js判断超时
(function () {
var startTime = (new Date).getTime(), //进入页面时间
interval = 0, //进入页面到现在间隔了多少秒
clock;
//每500毫秒计算一次,这里你自己修改
clock = setInterval(function () {
interval = Math.ceil(((new Date).getTime() - startTime) / 1000);
if (interval > 2) { //这里是2秒判断
clearInterval(clock);
callback();
}
}, 500);
function callback() {
//实现功能
alert('这里判断你的请求有没有成功');
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment