关于ajax性能优化的问题
function createXMLHttpRequest() {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}
function doRequestUsingGET()
{
createXMLHttpRequest();
var queryString = "RatioShowSevlet?timeStamp=" + new Date().getTime();
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("GET", queryString, true);
xmlHttp.send(null);
}
function handleStateChange()
{
if(xmlHttp.readyState == 4)
{
if(xmlHttp.status == 200)
{
parseResults();
setTimeout("doRequestUsingGET()",3000);
}
}
}
function parseResults()
{
var results = xmlHttp.responseXML;
var record = null;
var recordes = results.getElementsByTagName("record");
var temp;
var temp2;
var showcolor;
var Divid;
record = recordes[0];
if(nTurnTable == 0)
{
temp = record.getElementsByTagName("sum_amount")[0].firstChild.nodeValue;
Divid = eval("Sum_Amount" + (nTurnTable + 1));
if(Divid.innerText != temp)
Divid.innerText = temp;
}
for(var i = 1; i<recordes.length; i++)
{
var CellId;
if(nTurnTable == 0)
{
CellId = i;
}
else if(nTurnTable == 1)
{
CellId = i + 50;
}
else if(nTurnTable == 2)
{
CellId = i + 60 + nTurnTable2 * 2;
}
record = recordes;
Divid = eval("Rate_" + CellId);
temp = record.getElementsByTagName("rate")[0].firstChild.nodeValue;
if(Divid.innerText != temp)
Divid.innerText = temp;
temp = record.getElementsByTagName("chkcolor")[0].firstChild.nodeValue;
if(temp == "BLUE")
{
showcolor = "#bbbbee"
}
else if(temp == "GREEN")
{
showcolor = "#bbeebb"
}
else if(temp == "YELLOW")
{
showcolor = "#eeeebb"
}
else if(temp == "ORANGE")
{
showcolor = "#eeaa33"
}
else if(temp == "RED")
{
showcolor = "#eebbbb"
}
else
{
showcolor = temp;
}
temp2 = record.getElementsByTagName("show")[0].firstChild.nodeValue;
if(temp2 == "0" && document.all("Tbl_" + CellId).bgColor != "#919191")
{
document.all("Tbl_" + CellId).bgColor = "#919191";
}
else if (temp2 == "1" && document.all("Tbl_" + CellId).bgColor != showcolor)
{
document.all("Tbl_" + CellId).bgColor = showcolor;
}
Divid = eval("Profit_" + CellId);
temp = record.getElementsByTagName("profit")[0].firstChild.nodeValue;
if(Divid.innerText != temp)
{
Divid.innerText = temp;
if(temp >= 0)
{
Divid.style.color = "BLUE";
}
else
{
Divid.style.color = "RED";
}
}
Divid = eval("Switch_" + CellId);
temp = record.getElementsByTagName("active")[0].firstChild.nodeValue;
if(temp == "1")
{
temp = "○";
temp2 = "BLUE"
}
else if(temp == "0")
{
temp = "×";
temp2 = "RED"
}
if(Divid.value != temp)
{
Divid.value = temp;
Divid.style.color = temp2;
}
}
}
|