. NET AJAX Request data Submission Instance _ Practical skills

Source: Internet
Author: User
Tags md5

This example describes the. NET AJAX Request data submission implementation method. Share to everyone for your reference. Specifically as follows:

Copy Code code as follows:
<%@ Page language= "C #" inherits= "system.web.mvc.viewpage<dynamic>"%>

<title>ajax Request </title>
<link type= "Text/css" rel= "stylesheet" href= "/content/style.css"/>
<script type= "Text/javascript" src= "/scripts/jquery-1.8.3.min.js" ></script>
<script type= "Text/javascript" src= "/scripts/js.js" ></script>
<body>
<!--top +logo+ navigation-->
<div class= "Logo_box" >
<div id= "logo" >
<a title= "Ajax request" >ajax request </a></div>
</div>
<!---->
<div class= "Logincon" >
<div class= "Loginbanner" >
</div>
<div class= "Loginbox" >
<span class= "FL" > member Login </span><span class= "NewUser" > No account? <a href= ' <%=url.action ("register", "account")%> ' > Register now </a></span>
<form id= "FormData" >
<div class= "LoginForm" >
<div class= "InputBox" >
<input type= "text" name= "user" value= "username/mobile number" class= "UserId"/>
</div>
<div class= "InputBox" >
<input type= "text" value= "password" class= "TextStyle"/>
<input type= "password" name= "pwd" class= "passwordstyle none"/>
</div>
<div class= "warn" > Username or password Error! </div>
<div class= "Remember" >
<label>
<input type= "checkbox" Name= "remembered" checked/>
Automatic login </label>
<a class= "Forget" href= ' <%=url.action ("resetpwd", "Login")%> ' > Forgot password? </a>
</div>
<input class= "loginbtn" type= "button" value= "Login"/>
</div>
</form>
</div>
</div>
</body>
<script type= "Text/javascript" >
$ (function () {
$ ('. Userid,.passwordstyle '). On (' KeyUp ', function (e) {
if (E.keycode = = 13) {
$ ('. Loginbtn '). Trigger (' click ');
}
});
$ ('. Loginbtn '). On (' click ', function () {
$ (". Warn"). Hide ();
var pwd = $ ('. Passwordstyle '). Val ();
if (pwd = = "") {
$ (". Warn"). Show (). HTML (' Please enter password ');
return false;
}
var data = $ ("#formData"). Serialize ();
$.post ("/login/checklogininfo", data, function (ajaxobj) {
Postback content {status:1 (Success)/0 (fail),}
if (ajaxobj.status = 0 | | | status = NULL) {
$ (". Warn"). Show (). HTML (' username or password is wrong! ');
} else {
Login successful, jump all set page
window.location = '/membercenter/index ';
}
}, "JSON");
});
});
</script>

Controller

Copy Code code as follows:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using SYSTEM.WEB.MVC;
Using System.Text;

Namespace Bigtree. Controllers
{
Using Bigtree. Models;
Using Bigtree. Model;
Using Bigtree.lib;
Using System.Net.Mail;
Using System.Text.RegularExpressions;

public class Logincontroller:controller
{
Public ActionResult Index ()
{
return View ();
}
<summary>
Check Login
</summary>
<param name= "F" ></param>
<returns></returns>
[HttpPost]
Public ActionResult Checklogininfo (formcollection f)
{
Try
{
Post:user, PWD, remembered
String user = f["user"]. Trim ();
string pwd = f["pwd"]. Trim ();
String remembered = f["remembered"]. Trim ();

Jsonresult res = new Jsonresult ();
if (string. IsNullOrEmpty (user) | | String. IsNullOrEmpty (PWD))
{
Res. Data = new {status = 0};
}
MD5 Encrypted password
PWD = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile (pwd, "MD5"). ToLower ();
Reading from a database
Common.webuser account = Memberinfoservice.getmemberidforcheck (user, PWD);
if (account = = null)
{
Res. Data = new {status = 0};
}
Else
{
{status:1 (Success)/0 (fail),}
Res. Data = new {status = 1};
TODO: Login successful, log logged in user information save login status
Funsession.setsession (account);

Do you remember to log in
if (remembered = "on")
{
HttpCookie cookie = new HttpCookie ("Logininfo", account. Id.tostring ());
3 days effective
Cookie. Expires.adddays (3);
RESPONSE.COOKIES.ADD (cookie);
}
Else
{
HttpCookie cookie = new HttpCookie (account. Id.tostring (), account. Id.tostring ());
Make invalid
Cookie. Expires.addyears (-1);
RESPONSE.COOKIES.ADD (cookie);
}
}
return res;
}
catch (Exception ex)
{
Throw ex. innerexception;
}
}
}
}

I hope this article will be described to you. NET program design helps.

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.