Because the work needs to study the JS Ajax, below is the result.
There are three main parts:
One, JS part of the Friendship notice in the JS section of the $ ("#btn_login") in the return false; This can stop the rotary server or it will refresh.
Copy Code code as follows:
$ (document). Ready (function () {
$ ("#btn_login"). Click (function () {
Postlogin ();
return false;
});
});
function Postlogin () {
if (Checkusername () && checkuserpwd ()) {
var username = $ (' #txt_loginname '). Val ();
var Userpass = $ (' #txt_loginpass '). Val ();
$.post (".. /userlogin.aspx ", {username:username, userpass:userpass}, function (Result) {
if (result = = "1") {
Alert ("Login succeeded!") ");
else if (result = = "3") {
Alert ("Incorrect username!");
else if (result = = "2") {
Alert ("Incorrect password!");
} else {
Alert ("Login failed!")
}
});
}
}
function Checkusername () {
if ($ ("#txt_loginname"). Val (). length = = 0) {
Alert (' User name cannot be empty! ');
return false;
} else {
return true;
}
}
function Checkuserpwd () {
if ($ ("#txt_loginpass"). Val (). Lenght = 0) {
Alert (' Incorrect password! ');
return false;
} else {
return true;
}
}
Second, the page part
Copy Code code as follows:
<table width= "100%" border= "0" cellspacing= "0" cellpadding= "0" >
<tr>
<TD width= "32%" height= "Notoginseng" valign= "middle" > Username:</td>
<TD width= "68%" valign= "Middle" >
<input type= "text" name= "Txt_loginname" id= "Txt_loginname" class= "input_1"/>
</td>
</tr>
<tr>
<TD height= "Notoginseng" valign= "middle" > Password:</td>
<TD valign= "Middle" >
<input type= "Password" name= "Txt_loginpass" id= "Txt_loginpass" class= "Input_2"/>
</td>
</tr>
<!--<tr>
<TD height= "Notoginseng" valign= "middle" > Verification Code:</td>
<TD valign= "Middle" >
<input type= "text" name= "textfield3" id= "textfield3" class= "Input_3" style= "Float:left"/>
<span style= "Float:left; margin-left:6px; " ></span></td>
</tr>-->
<tr>
<TD colspan= "2" >
<input type= "image" Name= "Btn_login" id= "Btn_login" src= "Images/img_4.gif"/>
<input type= "image" Name= "input" src= "Images/img_5.gif"/>
<input type= "image" Name= "input" src= "Images/img_6.gif"/>
</td>
</tr>
</table>
Third, the background part is in JS to the processing of login Information page
Copy Code code as follows:
protected void Page_Load (object sender, EventArgs e)
{
String username = request.form["username"];
String userpass = request.form["Userpass"];
T_user User = Usermanager.loginpassword (username, userpass);
if (user!= null)
{
session["user"] = user;
Response.Write ("1"); Login successful
Response.End ();
}
Else
{
if (Usermanager.onlyone (username) >= 1)
{
Response.Write ("2"); The password is not correct
Response.End ();
}
Else
{
Response.Write ("3"); User name does not exist
Response.End ();
}
}
}