Instance:
1. Request Page Ajax.aspx
HTML code
Copy Code code as follows:
<div>
<input id= "txtname" type= "text"/><input type= "button" value= "to see if the username exists" id= "btn" onclick= "Judgeusername ();" />
<div id= "Showresult" style= "Float:left" >div>
Div>
JS Code
Copy Code code as follows:
<script type= "Text/javascript" src= "Css/jquery-1.3.2.js" ></script>
<script type= "Text/javascript" >
function Judgeusername ()
{
$.ajax ({
Type: "Get",
URL: "Ajaxuserinfomodify.aspx",
DataType: "HTML",
Data: "Username=" +$ ("#txtName"). Val (),
Beforesend:function (XMLHttpRequest)
{
$ ("#showResult"). Text ("Query Now");
Pause (this,100000);
},
Success:function (msg)
{
$ ("#showResult"). HTML (msg);
$ ("#showResult"). CSS ("Color", "red");
},
Complete:function (Xmlhttprequest,textstatus)
{
Hide query Picture
},
Error:function ()
{
Error handling
}
});
}
</script>
2, Page ajaxuserinfomodify.aspx
Background code
Copy Code code as follows:
protected void Page_Load (object sender, EventArgs e)
{
String userName = request.querystring["UserName"]. ToString ();
if (UserName = "James Hao")
{
Response.Write ("User name already exists!") ");
}
Else
{
Response.Write ("You can use this username!") ");
}
}
3 , run the interface
(1) Initialization interface
(2) Query prompt page
(3) Verify that the user name already exists on the page
(4) Verify that the user name does not exist on the page
The ability to verify that the user name exists has been completed by Ajax.