Implementing Ajax based on jquery to verify the existence of a user name instance _jquery

Source: Internet
Author: User
Tags error handling script tag

This article to share based on jquery implementation of Ajax to verify the existence of the user name implementation code, need the code farmers can refer to the source code of this article.

Jquery.ajax Overview

HTTP requests load remote data.

Implemented through the jquery underlying AJAX. Simple and easy-to-use high-level implementation see $.get, $.post, etc. $.ajax () returns the XMLHttpRequest object that it created. In most cases you do not need to manipulate the object directly, but in special cases you can use it to manually terminate the request.

$.ajax () has only one parameter: The parameter Key/value object, which contains the configuration and callback function information. Detailed parameter options see below.
Note: If you specify the DataType option, make sure that the server returns the correct MIME information (such as the XML return "Text/xml"). The wrong MIME type can cause unpredictable errors.

Note: If datatype is set to script, all post requests will be converted to get requests at remote request (not under the same domain). (because it will be loaded using the DOM's script tag)
In JQuery 1.2, you can load JSON data across domains and use it to set the data type to JSONP. When calling a function using JSONP form, such as "myurl?callback=?" JQuery is automatically replaced? To the correct function name to execute the callback function. When the data type is set to "Jsonp", JQuery automatically invokes the callback function.

Parameter list:

Here are a few Ajax event parameters: Beforesend, Success, complete, error. We can define these events to deal well with each of our AJAX requests. Notice that this in these AJAX events is the information about the options for the Ajax request (refer to the picture of this when you say Get () method).
Read the argument list carefully, and if you want to use jquery for AJAX development, you need to be familiar with these parameters.
Example:

1. Request Page Ajax.aspx

HTML code

<div> 
<input id= "txtname" type= "text"/><input type= "button" value= "to see if the user name exists" id= "btn" onclick= " Judgeusername (); "/> <div id=" Showresult "style=" Float:left " 
>div> 
div> 

JS Code

<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}} 
); 
 

2, Page ajaxuserinfomodify.aspx

Background code

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!") "); 
} 
} 

The above is the entire content of this article, I hope to help you learn.

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.