Ajax authentication username and password, ajax authentication Username
1 var user = form. name. value; 2 var password = form. password. value; 3 var url = "chkname. php? User = "+ user +" & password = "+ password; // previously, I only knew That ajax was used to detect the user name. In the past, I could also detect the password. 4 xmlhttp. open ("GET", url, true); 5 xmlhttp. onreadystatechange = function () {6 if (xmlhttp. readyState = 4) {7 var msg = xmlhttp. responseText; 8 if (msg = '1') {9 alert ('user name or Password error !! '); 10 form. password. select (); 11 form. check. value = ''; 12 code (form); 13 return false; 14} if (msg =" 3 ") {15 alert (" username occupied, please enter it again! "); 16 return false; 17} else {18 alert ('Welcome '); 19 location. reload (); 20} 21} 22} 23 xmlhttp. send (null); 24 return false;
Php uses ajax to verify the user name and the user in the database
Step 1: A jq js File
<! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "www.w3.org/TR/html4/loose.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Title> Login </title>
<Script type = "text/javascript" src = "<? Php echo $ this-> baseUrl?> /Public/js/jq1.7.js "> </script>
<Script language = "javascript">
$ (Document). ready (function (){
$ ("# Submit"). click (function (){
If ($ ("# uname"). val () = "" | $ ("# upas"). val () = ""){
Alert ("the user name or password cannot be blank ");
Return false;
} Else {
$ ("# Showerrormessage"). load (
'<? Php echo $ this-> baseUrl?> /Index/login ',
{Uname: $ ("# uname"). val (), upas: $ ("# upas"). val ()},
Function (data ){
If (data = 1 ){
$ ("# Showerrormessage" login .html ('login success !!! ');
} Else {
$ ("# Showerrormessage" cmd.html ('login error ~~~ ');
}
}
);
}
});
});
</Script>
</Head>
<Body>
<Form id = "form1" name = "form1" method = "post" action = "">
Username: <input type = "te ...... remaining full text>
I want to use jsp + ajax technology for login user name and password verification, mainly using javascript
Ajax, I will. But JSP, I am just a half-hanger.