$(document).ready(function(){
c = setInterval(checkIsExist,10000)//每10秒执行一次checkIsExist方法
})
function checkIsExist(){
$.ajax({
type: "POST",
url: "/SecondServlet",
data: "date="+new Date(),
success: function(rtmsg){
if(rtmsg == 'exist'){
$("#download").html("<button onclick=\"window.open('/ArticleServlet')\">下载</button>")
window.clearInterval(c)
}
}
})
}
在JavaScript中提供了定时执行函数setTimeout:setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式。语法setTimeout(code,millisec)参数描述code必需。要调用的函数后要执行的 JavaScript 代码串。millisec必需。在执行代码前需等待的毫秒数。用法如下:<html><head><script type="text/javascript">function timedMsg(){var t=setTimeout("alert('5 seconds!')",5000) //等待5秒执行alert}</script></head><body><form><input type="button" value="Display timed alertbox!"onClick="timedMsg()"></form><p>Click on the button above. An alert box will bedisplayed after 5 seconds.</p></body></html>