Home >Web Front-end >JS Tutorial >Ajax submission form to achieve web page refresh registration example_Basic knowledge

Ajax submission form to achieve web page refresh registration example_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 16:49:181760browse

Ajax no refresh

Copy code The code is as follows:

var xmlHttp;
uName() //User When name 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. "'"; //Will jump to the page where the user name is detected
xmlHttp.open("get",url,true ); //Submit the form to the url using get mode; and start one-step processing
xmlHttp.send(null); //Send
}
}
deal()
{
//alert(xmlHttp.readystate "__" xmlHttp.status);
if(xmlHttp.readystate!=4)
{return; }

if(xmlHttp.status!=200) //When equal to 500, it 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="This username has been used!";
}
else
{
all.l1.innerText="√";
}

}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn