Implementation code for AJAX verification of the existence of user names based on jquery _jquery

Source: Internet
Author: User
Tags error handling
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.