1. Use the JavaScriptjs file to verify whether the user name exists.
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 (); /* --------- difference between GET and POST ---------- 1. get adds the parameter data queue In the URL referred to by the ACTION attribute of the form, the values correspond to each field in the form one by one, which 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 value of the variable. 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. open ("GET", option. url, true); // request. open ("POST", option. url, true); // set this attribute before sending a request to obtain the server's preparation status request. onreadystatechange = ResponseRequest; request. send (null);}/* request. readyState = 4 indicates that the server has received a response request. status = 200. The status value of the HTTP server response indicates that the request is in the ready status of HTTP. 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. */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 () {/* 1, the url is the page to be linked and the value to be passed in. Pass in the past, let the dynamic page execute 2, Default. aspx is the page 3 for this execution, and name is the passed parameter name 4, document. getElementById ('text1 '). value passed to parameter value 5, message. message returned from the server after responseText is successful */var option = {url: "Default. aspx? Name = "+ document. getElementById ('text1'). value, Success: function (message) {alert (message. responseText) ;}; new ajax (option );}
Aspx 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 and can be used! ");} This. Response. End ();}
2. Implemented through Jquery:
$(document).ready(function(){ $("#Button1").click(function(){ $.ajax({type:"GET",url:"ResponsePage.aspx?name="+document.getElementById('Text1').value,success:function(message) { alert(message); }}); }); });