Ajax make Form Validation sample

Source: Internet
Author: User
Tags functions return window
Ajax functions are mainly used in JS, Ajax does not require ASP, ASP is responsible for the background display and operation of the server data.
You can think like this:
1. Write form the first item (such as user name)
2.onblur event (lost focus) begins validation when it occurs, onblur= "Checkusername ()"
3.js send a request to the first ASP (assuming ajaxusername.asp) if the user is found from the database, give 1 (ajaxusername.asp all content is a 1) as
<%
if (User.exist ()) Response.Write "1"
%>
4.js received, the checkuser () function is automatically executed.
CheckUser the user name line background color change, and show "the user has already existed"

You wrote the ASP section yourself. Some JS code is given below.
<script>
/* The following functions generally do not need to change * *
var Ajax;
function Createajax () {
if (window. XMLHttpRequest) {
Ajax = new XMLHttpRequest ();
}else if (window. ActiveXObject) {
Ajax = new ActiveXObject ("Microsoft.XMLHTTP");
}
}
function SendData (url_,sendtext_) {
Ajax.open ("POST", url_,true);
Ajax.onreadystatechange = checkuser;
Ajax.send (Sendtext_);
}
function Checkajaxstatus (ajax_) {
if (ajax_.readystate = 4)
if (Ajax_.status = 200)
return true;
return false;
}
/* The above function generally does not need to change * *
function checkuser () {
if (! Checkajaxstatus (Ajax)) return;
The ASP returns the processing of the result to the fruit. The server returns the ajaxusername.asp, which is stored in the Ajax.responsetext property.

}

function Checkusername () {
Createajax ();
SendData ("ajaxusername.jsp", "username=" + name);
}

</script>

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.