Ajax and asp.net check for the existence of user names without refreshing

Source: Internet
Author: User
Tags html header

Ajax and asp.net check for the existence of user names without refreshing

/*
1. the url is the page to be linked and the pass-through value. The pass-through value is used for dynamic page execution.
2, default. asp tutorial x is the page for this execution
3. name is the name of the parameter passed in.
4, document. getelementbyid ('text1'). The parameter value passed by value
5. The message returned from the server after message. responsetext is successful
*/

Jquery code

 

$ (Document). ready (function (){
$ ("# Button1"). click (function (){
$. Ajax ({
Type: "get ",
Url: "responsepage. asp tutorial x? Name = "+ document. getelementbyid ('text1'). value,
Success: function (message ){
Alert (message );
}

});

});
});

Asp.net tutorial File

 

If (request ["name"]! = Null)
{
This. response. clear ();
String name = request ["name"]. tostring ();
If (name = "1 ")
{
Response. write ("the user name already exists. Please enter another user name! ");
}
Else
{
Response. write ("this user name is not registered. You can use it! ");
}

This. response. end ();
}

Javascript tutorial script file

 

Var ajax = function (option)
{
Var request;
Var createrequest = function ()
{
// Var request;
If (window. xmlhttprequest)
{
Request = new xmlhttprequest ();
}
Else
{
Try
{
Request = new activexobject ("microsoft. xmlhttp ");
}
Catch (e)
{
Request = new activexobject ("msxml2.xmlhttp ");
}
}
Return request;
}
Var sendrequest = function ()
{
Request = createrequest ();
Request. open ("get", option. url, true );
// Request. open ("post", option. url, true );
// Set this attribute before sending a request to obtain the preparation status on the server
Request. onreadystatechange = responserequest; www. bKjia. c0m
Request. send (null );
}

Var responserequest = function ()
{
Alert ("http Readiness:" + request. readystate );
If (request. readystate = 4)
{
If (request. status = 200)
{
Alert ("everything goes well! ");
Option. success (request );
}
Else
{
Alert ("error, error message:" + request. status );
Option. failure (request );
}
}
}
Sendrequest ();
}
// Determine whether the input value exists
Function getis ()
{
Var option =
{
Url: "default. aspx? Name = "+ document. getelementbyid ('text1'). value,
Success: function (message)
{
Alert (message. responsetext );
}
};
New ajax (option );
}

/* --------- Difference between get and post ------------
1. get adds the parameter data queue to the url referred to by the action attribute of the submission form. The values correspond to each field in the form one by one and can be seen in the url.
Post uses the http post mechanism to place fields in the form and their content in the html header and send them to the url address referred to by the action attribute. You cannot see this process.
2. For the get method, the server uses request. querystring to obtain the variable value,
For the post method, the server uses request. form to obtain the submitted data.
You can use request to obtain parameters in either of the two methods.
3. The data volume transmitted by get is small and cannot exceed 2 kb.
The amount of data transmitted by post is large, which is generally not restricted by default.
4. Low get security and high post security.
5. When submitting a form, we usually use the post method. When we want to transmit a large data file, we need to use post.
When the passed value only needs to be in the parameter mode (this value is not greater than 2 kb), use the get method.
/*
Request. readystate = 4 indicates that the server has received a response.
Request. status = 200, http server response status value, indicating that everything goes smoothly
Http readiness
0: the request is not sent (before open () is called ).
1: The request has been created but has not been issued (before sending () is called ).
2: The request is being processed (the content header can be obtained from the response ).
3: The request has been processed, and some data is usually available in the response, but the server has not yet completed the response.
4: The response has been completed. You can access the server response and use it.
*/

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.