ajax的定时调用每5秒调用一次
程序员文章站
2023-11-14 20:09:04
复制代码 代码如下: function initxmlrequest(){ if (window.activexobject) { xmlrequest = new act...
复制代码 代码如下:
function initxmlrequest(){
if (window.activexobject) {
xmlrequest = new activexobject("microsoft.xmlhttp");
} else {
if (window.xmlhttprequest) {
xmlrequest = new xmlhttprequest();
}
}
}
function sendhttprequest(){
initxmlrequest();
var url = "monitor!taskdata.action"; //调用的servlet
if (xmlrequest) {
xmlrequest.open("post", url, true);
xmlrequest.send(null);
xmlrequest.onreadystatechange = isdataexists;
//使用方法回调,每5秒调用一次
settimeout("sendhttprequest()",5000);
}
}
function isdataexists(){
if (xmlrequest.readystate == 4) {
if (xmlrequest.status == 200) {
var data = eval("("+xmlrequest.responsetext+")");
// 获取tbody的表格内容
var tasktable = document.getelementbyid("tasktbody");
for(var i=tasktable.childnodes.length-1;i>=0;i--){
tasktable.removechild(tasktable.childnodes[i]);
}
$.each(data, function(i,val){
var newtr = tasktable.insertrow(tasktable.rows.length);
newtr.id="taskdata_"+(i+1);
newtr.ondblclick=getdetail;
newtr.onclick=selectrow;
backcolor(val.taskstatus,newtr);
var newnametd=newtr.insertcell(0);
newnametd.innerhtml = val.taskname;
newnametd.id="taskname_"+(i+1);
var newstatustd=newtr.insertcell(1);
newstatustd.innerhtml = val.taskstatus;
newstatustd.id="taskstatus_"+(i+1);
var newargtd=newtr.insertcell(2);
newargtd.innerhtml = val.data_start_time;
var newotherargtd=newtr.insertcell(3);
newotherargtd.innerhtml = val.schedule_interval;
var newdateformattd=newtr.insertcell(4);
newdateformattd.innerhtml = val.next_execution_time;
var newbackwordtd=newtr.insertcell(5);
newbackwordtd.innerhtml = val.taskdetailscount;
var newprioritytd=newtr.insertcell(6);
newprioritytd.innerhtml = val.statusruncount;
var newlefttd=newtr.insertcell(7);
newlefttd.innerhtml = val.statusfinishcount;
var newlefttimetd=newtr.insertcell(8);
newlefttimetd.innerhtml = val.statuserrorcount;
});
}
}
}