Ajax instance: XMLHttpRequest creates a registration page

Source: Internet
Author: User

Bkjia.com documentAfter reading ajax for a long time, there are few examples by hand. Today, I decided to write one by myself. The function is very simple and a simple user name registration function is implemented, at the same time, the user input is verified on the server side, and the user name is not saved in the database. application · object simulation is used here. After a long time, I got it done. I encountered a lot of problems and finally solved them. The interesting thing is that after I wrote the example, I ran normally in firefox, but I had a problem in ie, the registered user name still shows that the registration was successful. After checking for a long time, I did not figure out the reason. Finally, I reviewed a video tutorial I had read before and realized that it was caused by the cache of IE, it's easy to cheat ie with a trick! I feel very rewarding!

The following code is used:

 Html code of the registration page:

<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN"> 

Tip: the code can be modified before running!

 Server asp code:

Reference content is as follows:
<% @ Page language = "java" import = "java. util. *" pageEncoding = "UTF-8" %>

<%
String type = request. getParameter ("type ");
If (type. equals ("username ")){
String username = request. getParameter ("username ");

If (username! = Null & username. length ()> 0 ){
If (application. getAttribute (username )! = Null ){

Out. println ("Username is exist! ");
} Else {
Out. println ("Username is OK! ");
}


} Else {
Out. println ("Username is need! ");
}

} Else if (type. equals ("password ")){
String password = request. getParameter ("password ");
If (password! = Null & password. length ()> 0 ){
Out. println ("password is OK ");

} Else {
Out. println ("Password is need! ");

}

} Else if (type. equals ("password2 ")){
String password2 = request. getParameter ("password2 ");
If (password2! = Null & password2.length ()> 0 ){
String password = request. getParameter ("password ");
If (password2.equals (password )){
Out. println ("Password2 is OK! ");
} Else {

Out. println ("Password2 is not equal Password! ");
}

} Else {
Out. println ("Password2 is need! ");

}

} Else if (type. equals ("submit ")){

Boolean regFlag = true;

String username = request. getParameter ("username ");
String password = request. getParameter ("password ");
String password2 = request. getParameter ("password2 ");

If (username! = Null & username. length ()> 0 ){

If (username! = Null & username. length ()> 0 ){
If (application. getAttribute (username )! = Null ){
RegFlag = false;
Out. println ("username is exist! ");
}
}

} Else {
Out. println ("Username is needed! <Br/> ");
RegFlag = false;
}

If (password! = Null & password. length ()> 0 ){

} Else {
Out. println ("Password is need! <Br/> ");
RegFlag = false;

}
If (password2! = Null & password2.length ()> 0 ){

If (password2.equals (password )){

} Else {

Out. println ("Password2 is not equal Password! <Br/> ");
RegFlag = false;
}

} Else {
Out. println ("Password2 is need! <Br/> ");
RegFlag = false;

}
If (regFlag = true ){
Application. setAttribute (username, username );

Out. println ("Register is successful! ");

}

}
%>

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.