js实现定时任务,每隔N秒请求后台

见如下代码:


//生成了随机秒数60-150之间
	var num = Math.round(Math.random()*90+60);
	alert(num);
	//循环执行,每隔60-150秒钟执行一次showMsgIcon() 
	window.setInterval(showMsgIcon, 1000*num); 
	function showMsgIcon(){ 
		$.getJSON("${ctx}/todoTask/getTodoTaskList.do?processed=0", function(result){
			if(result.rows.length > 0){
				var msgPicFadeOutIn = setInterval(function(){$("#msgPic").fadeOut(500).fadeIn(500);}, 1000);
				$("#msgPic").attr("title", "您有待办任务、未读消息,点击查看");
				$("#msgPic").click(function(){
					if(msgPicFadeOutIn != ""){
						clearInterval(msgPicFadeOutIn);
						msgPicFadeOutIn = "";
					}
					$("#msgPic").fadeOut();
					toAction("/todoTask/showMyUnProcessedTask.do", "我的待办任务", this);
				});
			}else{
				$("#msgPic").fadeOut();
			}
		}); 
	}


你可能感兴趣的:(java知识,js实现定时任务,js每隔时间请求后台,js定时任务,js定时请求后台)