Ajax小应用函数

function Ajax(data)
{ 
  createXMLHttpRequest();
  if(data==document.getElementById("username"))
  {
    xmlhttp.open("GET","user_ck.php?username="+data.value,true);       
    document.getElementById('username_notice').innerHTML = process_request;//显示状态
  }
  else if(data==document.getElementById("veruserid"))
  {
    xmlhttp.open("GET","user_ck.php?veruserid="+data.value,true);       
    document.getElementById("veruserid_notice").innerHTML = process_request;//显示状态
  }
   else if (data==document.getElementById("verify"))
  {
	xmlhttp.open("POST","veruser_check.php",true);
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    document.getElementById("verify_notice").innerHTML = process_request;//显示状态
   }//"checkcode="+checkcode.value+"&username="+ 
   xmlhttp.onreadystatechange=function()
	{  //alert("zhong");
		if (4==xmlhttp.readyState)
		{   
			if (200==xmlhttp.status)
			{   
				var responseText = xmlhttp.responseText;
				responseText= responseText.replace(/(^\s*)|(\s*$)/g,"");
				if (responseText=="true" )
				{   
				   	ck_user(data,"true");
				}
				else
				{  
				   ck_user(data,"false");
				}
			}
			else
			{
				alert("发生错误!");
			}
		}
	}
 if(data==document.getElementById("veruserid")||data==document.getElementById("username"))
        {      
		       xmlhttp.setRequestHeader("If-Modified-Since","0");
			   xmlhttp.send(null);
		 }
 else if (data==document.getElementById("verify"))		
 		{
			 xmlhttp.send("veruserid="+document.getElementById("veruserid").value+"&veruserpwd="+document.getElementById("verpassword").value);
		}
}

你可能感兴趣的:(SHELL_SCRIPT)