CNET中国旗舰网站

ZDNet China | CNET科技资讯网 | 政府采购 | 行业网站联盟





 
标题: [转贴] 关于ajax性能优化的问题
jkathy
银牌会员
Rank: 5Rank: 5



UID 307038
精华 0
积分 2118
帖子 188
威望 1002
ZD币 286 元
阅读权限 100
注册 2008-3-13
状态 离线
  楼主
发表于 2008-4-17 13:31  资料  个人空间  短消息  加为好友 
开发者在线

关于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;   
  }   
  }   
  }




顶部
 



当前时区 GMT+8, 现在时间是 2009-7-4 23:08

  Powered by Discuz! 5.5.0 © 2001-2007 Comsenz Inc.
Processed in 0.192165 second(s), 3/3 queries

清除 Cookies - 联系我们 - ZDNetChina中文社区 - 无图版