PHP+Ajax 用户名检测详解

本例一共需3个文件



  Ajax.js
  var xmlHttp;
  //实例化过程
  function S_xmlhttprequest(){
  if(window.ActiveXObject){
  xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');
  }else if(window.XMLHttpRequest){
  xmlHttp=new XMLHttpRequest();
  }
  }
  function funphp100(name){
  //获取form内容
  //http://www.ruoshuiyx.com 沈阳网站建设
  var f=document.myform.user.value;
  //引用实例化过程
  S_xmlhttprequest();
  //打开请求
  xmlHttp.open("GET","index.php?id="+f,true);
  //准备就绪执行
  xmlHttp.onreadystatechange=byphp;
  xmlHttp.send(null);
  }
  function byphp() {
  if(xmlHttp.readyState== 1) {
  document.getElementById('php100').innerHTML = "";
  }
  if(xmlHttp.readyState== 4 ){
  if(xmlHttp.status == 200) {
  var byphp100 = xmlHttp.responseText;
  document.getElementById('php100').innerHTML = byphp100;
  }
  }
  }
  For.php
  
  
  用户名//http://www.ruoshuiyx.com 沈阳网站建设:
  
  
  Index.php
  
  if($id=$_REQUEST[id])
  {
  //for ($i=1;$i<3;$i++)
  //{
  // echo$id;
  // sleep(1);//
  /