js 中 ajax的实现实例

function ajax(url, vars, callbackFunction){
  var request = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0");
  request.open("GET", url, true);
  request.onreadystatechange = function(){
    if (request.readyState == 4 && request.status == 200){
      if (request.responseText){        
        callbackFunction(request.responseText);
      }
    }
  };
  request.send(vars);
}

function getinfo(){
  state.innerHTML = "(载入中...)";
  //ajax("online/ajax.php?code=custList","",writedoc);
  setTimeout('ajax("online/ajax.php?code=custList","",writedoc)',1000);
}

function writedoc(str){
  state.innerHTML = " ";
  dline = str.split("`");
  if(dline[1] =="getInfo"){
    ballArr = dline[2].split("@");
    for(j=0;j<ballArr.length;j++){
      if(j >=10)break;
      if(ballArr[j]=='')continue;
      sline = ballArr[j].split("|");
      showdata(j,sline[0],sline[1],sline[2],sline[3],sline[4],sline[5]);
    }
  }
}

function showdata(index,aa,bb,cc,dd,ee,ff){
  eval("om_add_date_"+index).innerHTML = aa;
  eval("om_client_id_"+index).innerHTML = bb;
  eval("om_name_"+index).innerHTML = cc;
  eval("om_rate_"+index).innerHTML = dd;
  eval("om_amt_"+index).innerHTML = ee;
  if(ff==0)eval("om_state_"+index).innerHTML = "<font color=blue>A</font>";
  else if(ff==1)eval("om_state_"+index).innerHTML = "<font color=red>T</font>";
  else if(ff==2)eval("om_state_"+index).innerHTML = "<font color=red>J</font>";
}

posted @ 2011-05-31 15:36  叮/当  阅读(6103)  评论(0编辑  收藏  举报