k=setTimeout("test_username()",2000);//调用AJAX中的test_username()方法 //AJAX异步刷新 var xmlhttp;var time=0; function type_browser(){ xmlhttp = false; xmlhttpObj = ["MSXML2.XmlHttp.5.0","MSXML2.XmlHttp.4.0","MSXML2.XmlHttp.3.0","MSXML2.XmlHttp","Microsoft.XmlHttp"]; if(window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else if(window.ActiveXObject) { for(i=0;i<xmlhttpObj.length;i++) { xmlhttp = new ActiveXObject(xmlhttpObj); if(xmlhttp) { break; } } } else { alert("暂时不能创建XMLHttpRequest对象"); } return xmlhttp?xmlhttp:false; } function test_username(){ type_browser(); //var username=document.userform.username.value; xmlhttp.open("POST","<?=site_url('zpz/index2')?>",true); xmlhttp.onreadystatechange=getdata; xmlhttp.send(); k=setTimeout("test_username()",2000); } function getdata(){ var data=xmlhttp.responseText; //document.getElementById('tbody').innerHTML=null; document.getElementById('tbody').innerHTML=data; document.getElementById('test11').innerHTML=time; time++; }