Rookie Cai Ajax Review third article (Ajax no refresh login) _ajax related

Source: Internet
Author: User
OK, or as before, build a login.html page, to fill in the login information, and then build a dealdata.aspx page (of course, here with the general processing is the best: *.ashx), used for processing data.

In the login.html page, the code is as follows:

Copy Code code as follows:

<title> No Refresh login </title>
<script src= "Scripts/jquery-1.4.1.js" type= "Text/javascript" ></script>
<script type= "Text/javascript" >
$ (function () {
Element Binding Global Ajaxstart Event
$ ("#divMsg"). Ajaxstart (function () {
$ (this). Show (); Show what's inside span
})
Element Binding Global Ajaxstop Event
$ ("#divMsg"). Ajaxstop (function () {
$ (this). HTML ("Request processing is complete!"). "). Hide ();
})
$ ("#btnSure"). Click (function () {//Click button Event
var $name = $ ("#txtName");//Get Login name
var $pwd = $ ("#txtPwd");//Get password
if ($name. val ()!= "" && $pwd. Val ()!= "") {
Invoke the login () method
Login ($name. Val (), $pwd. Val ());
} else {
if ($name. val () = "") {//If the sign-in name is not empty
Alert ("Logon name cannot be empty!") ");
$name. focus ()//Get focused
return false;
} else {
Alert ("Password cannot be blank!") ");
$pwd. focus ();
return false;
}
}
})
})
function Login (name, password) {
$.ajax ({
Type: "POST",//The way the data is requested (post or get), default to get
URL: "Dealdata.aspx",//Send the requested address (default = Current page)
Data: "action=login&date=" + new Date () + "&name=" + name + "&pwd=" + password,//sent to the server
Data returned after a successful login
Success:function (data) {
if (data = = "True") {//based on the return value (Note: Ture should be wrong to write True)! )
Alert ("Login succeeded!") ");
window.location = "1.htm"; page to jump
} else {
Alert ("Logon name or password is wrong!) ");
return false;
}
}
});
}
</script>
<body style= "Text-align:center" >
<div> Login Name: <input type= "text" id= "txtname" value= ""/></div>
<br/>
<div> Password: <input type= "text" id= "txtpwd" value= ""/></div><br/>
<div>
<input type= "Reset" value= "OK" id= "Btnsure"/>
</div>
<span id= "divmsg" style= "Display:none;" > Sending Request ......</span>
</body>

In dealdata.aspx, its background code is as follows:
Copy Code code as follows:

public partial class ManageData:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
String name = System.Web.HttpUtility.UrlDecode (request["name");//Get Login name
string pwd = System.Web.HttpUtility.UrlDecode (request["pwd");//Get password
Response.Write (Login (name, pwd));
Response.End ();
}
private bool Login (string name, string pwd)
{
BOOL result = FALSE;
if (name = = "Vegetable" && pwd== "123456")
{
return true;
}
return result;
}
}

Well, children's shoes, you also hurriedly try it! No refresh, you can also!
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.