`
chun521521
  • 浏览: 277039 次
  • 性别: Icon_minigender_1
  • 来自: 长春
社区版块
存档分类
最新评论

js心跳

 
阅读更多

 

alive.jsp:

<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";

%>

 

<!DOCTYPE html>

<html lang="en">

<head>

<base href="<%=basePath%>" />

<script type="text/javascript" src="<%=basePath%>resources/js/jquery.min-1.9.1.js"></script>

<script type="text/javascript" src="<%=basePath%>resources/js/jquery-heartbeat.js"></script>

 

<script type="text/javascript">

$(function(){

$.jheartbeat.set({

url: '<%=basePath%>uias/heartBeat.do',

delay: 10000//10s 心跳时间

});

})

</script>

 

</body>

</html>

 

 

jquery-heartbeat.js:

$.jheartbeat = {

options : {

url : "heartbeat_default.asp",

delay : 10000,

div_id : "test_div"

},

 

beatfunction : function() {

 

},

 

timeoutobj : {

id : -1

},

 

set : function(options, onbeatfunction) {

if (this.timeoutobj.id > -1) {

clearTimeout(this.timeoutobj);

}

if (options) {

$.extend(this.options, options);

}

if (onbeatfunction) {

this.beatfunction = onbeatfunction;

}

 

// Add the HeartBeatDIV to the page

$("body").append("<div id=\"" + this.options.div_id + "\" style=\"display: none;\"></div>");

this.timeoutobj.id = setTimeout("$.jheartbeat.beat();", this.options.delay);

},

 

beat : function() {

$.ajax({

url : this.options.url,

dataType : "html",

type : "GET",

headers : {

delay : this.options.delay

},

error : function(e) {

$('#' + $.jheartbeat.options.div_id).append("Error Requesting Data");

},

success : function(data) {

$('#' + $.jheartbeat.options.div_id).html(data);

}

});

this.timeoutobj.id = setTimeout("$.jheartbeat.beat();", this.options.delay);

this.beatfunction();

}

};

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics