-
-
Save cheenwe/2da05edee35c9dd50a2b41bc2208a38d to your computer and use it in GitHub Desktop.
js判断超时
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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