<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
專注于為中小企業(yè)提供成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)尚義免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了上千多家企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
<head runat="server">
<title>ajax請(qǐng)求</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>
</head>
<body>
<!--頂部+logo+導(dǎo)航-->
<div class="logo_box">
<div id="logo">
<a title="ajax請(qǐng)求">ajax請(qǐng)求</a></div>
</div>
<!---->
<div class="loginCon">
<div class="loginBanner">
<img src="/Images/4499633_182932517000_2.jpg" /></div>
<div class="loginBox">
<h3>
<span class="fl">會(huì)員登錄</span><span class="newUser">沒有賬號(hào)?<a href='<%=Url.Action("Register","Account") %>'>立即注冊(cè)</a></span></h3>
<form id="formData">
<div class="loginForm">
<div class="inputBox">
<input type="text" name="user" value="用戶名/手機(jī)號(hào)" class="userId" />
</div>
<div class="inputBox">
<input type="text" value="密碼" class="textStyle" />
<input type="password" name="pwd" class="passwordStyle none" />
</div>
<div class="warn">用戶名或密碼錯(cuò)誤!</div>
<div class="remember">
<label>
<input type="checkbox" name="remembered" checked />
自動(dòng)登錄</label>
<a class="forget" href='<%=Url.Action("ResetPwd","Login") %>' >忘記密碼?</a>
</div>
<input class="loginBtn" type="button" value="登錄"/>
</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('請(qǐng)輸入密碼');
return false;
}
var data = $("#formData").serialize();
$.post("/login/checkLoginInfo", data, function (ajaxObj) {
//回傳內(nèi)容{status: 1(success)/0(fail),}
if (ajaxObj.status == 0 || status == null) {
$(".warn").show().html('用戶名或密碼錯(cuò)誤!');
} else {
//登陸成功,跳轉(zhuǎn)都制定頁(yè)面
window.location = '/memberCenter/index';
}
}, "json");
});
});
</script>
</html>
控制器
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>
/// 檢查登陸
/// </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加密后的密碼
pwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "md5").ToLower();
//從數(shù)據(jù)庫(kù)讀取
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 };
//codego.net/#todo:登陸成功,記錄登陸用戶信息保存登陸狀態(tài)
FunSession.SetSession(account);
//是否記住登錄
if (remembered == "on")
{
HttpCookie cookie = new HttpCookie("LoginInfo", account.Id.ToString());
//3天有效
cookie.Expires.AddDays(3);
Response.Cookies.Add(cookie);
}
else
{
HttpCookie cookie = new HttpCookie(account.Id.ToString(), account.Id.ToString());
//使失效
cookie.Expires.AddYears(-1);
Response.Cookies.Add(cookie);
}
}
return res;
}
catch (Exception ex)
{
throw ex.InnerException;
}
}
}
}
分享題目:.NET的Ajax請(qǐng)求數(shù)據(jù)提交
路徑分享:http://aaarwkj.com/article32/pjcpsc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動(dòng)態(tài)網(wǎng)站、做網(wǎng)站、域名注冊(cè)、企業(yè)建站、外貿(mào)建站、用戶體驗(yàn)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)