Asp.net+jquery Ajax No Refresh Login Implementation Method _ Practical skills

Source: Internet
Author: User
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>
&LT;TD width= "32%" height= "Notoginseng" valign= "middle" > Username:</td>
&LT;TD width= "68%" valign= "Middle" >
<input type= "text" name= "Txt_loginname" id= "Txt_loginname" class= "input_1"/>
</td>
</tr>
<tr>
&LT;TD height= "Notoginseng" valign= "middle" > Password:</td>
&LT;TD valign= "Middle" >
<input type= "Password" name= "Txt_loginpass" id= "Txt_loginpass" class= "Input_2"/>
</td>
</tr>
<!--<tr>
&LT;TD height= "Notoginseng" valign= "middle" > Verification Code:</td>
&LT;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>
&LT;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 ();
}
}
}

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.