Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write a timed call to ajax once every 5 seconds

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

本篇内容介绍了"如何编写ajax的定时调用每5秒调用一次"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

复制代码 代码如下:

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[xss_clean] = val.taskname;

newNameTD.id="taskname_"+(i+1);

var newStatusTD=newTR.insertCell(1);

newStatusTD[xss_clean] = val.taskstatus;

newStatusTD.id="taskstatus_"+(i+1);

var newArgTD=newTR.insertCell(2);

newArgTD[xss_clean] = val.data_start_time;

var newOtherArgTD=newTR.insertCell(3);

newOtherArgTD[xss_clean] = val.schedule_interval;

var newdateformatTD=newTR.insertCell(4);

newdateformatTD[xss_clean] = val.next_execution_time;

var newbackwordTD=newTR.insertCell(5);

newbackwordTD[xss_clean] = val.taskdetailscount;

var newpriorityTD=newTR.insertCell(6);

newpriorityTD[xss_clean] = val.statusruncount;

var newleftTD=newTR.insertCell(7);

newleftTD[xss_clean] = val.statusfinishcount;

var newlefttimeTD=newTR.insertCell(8);

newlefttimeTD[xss_clean] = val.statuserrorcount;

});

}

}

}

"如何编写ajax的定时调用每5秒调用一次"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report