Ajax and ASP.net no refresh detect if the username exists

Source: Internet
Author: User
Tags html header http post

/*
1,url is to link the page and pass the past value, pass the past value, let dynamic page execution
2,default.asp tutorial x is the page to be executed for this
3,name is the name of the argument that passed.
4,document.getelementbyid (' Text1 '). Value passing past parameter values
5,message.responsetext the message returned from the server after success
*/

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 files

if (request["name"]!= null)
{
This.response.clear ();
String name = request["Name"].tostring ();
if (name = = "1")
{
Response.Write ("Username already exists, please fill in other username!");
}
Else
{
Response.Write ("The user name is not registered, you can use!");
}

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 property before sending a request to get ready status on the server
Request.onreadystatechange = Responserequest; Www.111cn.net
Request.send (NULL);
}

var responserequest = function ()
{
Alert ("Ready state of http:" +request.readystate);
if (request.readystate = 4)
{
if (Request.status = 200)
{
Alert ("All goes well!");
Option.success (Request);
}
Else
{
Alert ("An error occurred, the error message is:" +request.status);
Option.failure (Request);
}
}
}
SendRequest ();
}
Determine if the value entered exists
function Getis ()
{
var option =
{
URL: "Default.aspx?name=" +document.getelementbyid (' Text1 '). Value,
Success:function (Message)
{
alert (Message.responsetext);
}
};
New Ajax (option);
}

/*---------The difference between get and post------------
1, get is to add the parameter data queue to submit the form of the action attribute refers to the URL, the value and the form of each field one by one corresponding, in the URL can be seen.
Post is the HTTP post mechanism that places the fields in the form and their contents in the HTML header to the URL address that the action attribute refers to. This process is not visible to the user.
2, for Get way, the server end uses Request.QueryString to obtain the value of the variable,
For post methods, the server side uses Request.Form to obtain the submitted data.
The parameters of both methods can be obtained by request.
3. The amount of data transferred by get is less than 2KB.
Post transfers have a large amount of data, which is generally default to unrestricted.
4, get security is very low, post security is high.
5. When we submit the form, we usually use post, when we want to send a large data file, we need to use post.
When the value passed is only in parameter mode (this value is not more than 2KB), you can use Get method.
/*
Request.readystate = 4 indicates that the server has received a response
Request.status = = 200,http The state value of the server response, indicating that everything is going well
Ready status of HTTP
0: The request was not issued (before calling open ()).
1: The request has been established but has not been issued (before send () is called).
2: The request has been sent out in process (it is usually possible to get the content head from the response).
3: The request has been processed and there is usually some data available in the response, but the server has not completed the response yet.
4: The response is complete, 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.