Ajax without refresh
The code copy is as follows:
var xmlHttp;
uName() //When the username loses focus
{
if(all.uname.=="")
{
all.l1.innerHTML="cannot be empty!";
setTimeout("close(1)",1500);
return;
}
else
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.onreadystatechange=deal; //Callback function
var url="aJax.aspx?user='"+all.uname.+"'"; //It will be redirected to the page where the username is detected
xmlHttp.open("get",url,true); //Submit the form to url in get mode; and start a one-step process
xmlHttp.send(null); //Send
}
}
deal()
{
//alert(xmlHttp.readystate+"__"+xmlHttp.status);
if(xmlHttp.readystate!=4)
{return; }
if(xmlHttp.status!=200) //Equal to 500 is an error in the SQL statement or database
{return;}
//
var num = xmlHttp.responseText; //Receive information sent by the server
//alert(num);
all.l1.innerText="";
if(num>0)
{
all.l1.innerText="The username has been used!";
}
else
{
all.l1.innerText="√";
}
}