Regular ajax call every 5 seconds

Source: Internet
Author: User

Copy codeThe Code is as follows:
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 "; // call the servlet
If (xmlRequest ){
XmlRequest. open ("POST", url, true );
XmlRequest. send (null );
XmlRequest. onreadystatechange = isDataExists;
// Method callback, called every 5 seconds
SetTimeout ("sendHTTPRequest ()", 5000 );
}

}

Function isDataExists (){
If (xmlRequest. readyState = 4 ){
If (xmlRequest. status = 200 ){
Var data = eval ("(" + xmlRequest. responseText + ")");
// Obtain the tbody table content
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;
});

}
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.