亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

.NET的Ajax請求數(shù)據(jù)提交實例

 更新時間:2015年01月21日 11:31:55   投稿:shichen2014  
這篇文章主要介紹了.NET的Ajax請求數(shù)據(jù)提交實例,較為詳細(xì)的分析了Ajax請求、數(shù)據(jù)的提交以及參數(shù)的傳遞技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了.NET的Ajax請求數(shù)據(jù)提交實現(xiàn)方法。分享給大家供大家參考。具體如下:

復(fù)制代碼 代碼如下:
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %> 
 
<head runat="server"> 
    <title>ajax請求</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請求">ajax請求</a></div> 
    </div> 
    <!----> 
    <div class="loginCon"> 
        <div class="loginBanner"> 
            <img src="/Images/4499633_182932517000_2.jpg" /></div> 
        <div class="loginBox"> 
            <h2> 
                <span class="fl">會員登錄</span><span class="newUser">沒有賬號?<a href='<%=Url.Action("Register","Account") %>'>立即注冊</a></span></h2> 
 
            <form id="formData"> 
            <div class="loginForm"> 
                <div class="inputBox"> 
                    <input type="text" name="user" value="用戶名/手機(jī)號" class="userId" /> 
                </div> 
                <div class="inputBox"> 
                    <input type="text" value="密碼" class="textStyle" /> 
                    <input type="password" name="pwd" class="passwordStyle none" /> 
                </div> 
                <div class="warn">用戶名或密碼錯誤!</div> 
                <div class="remember"> 
                    <label> 
                        <input type="checkbox" name="remembered" checked /> 
                        自動登錄</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('請輸入密碼'); 
                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('用戶名或密碼錯誤!'); 
                } else { 
                    //登陸成功,跳轉(zhuǎn)都制定頁面 
                    window.location = '/memberCenter/index'; 
                } 
            }, "json"); 
        }); 
    }); 
</script> 
</html>

控制器

復(fù)制代碼 代碼如下:
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ù)庫讀取 
                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:登陸成功,記錄登陸用戶信息保存登陸狀態(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程序設(shè)計有所幫助。

相關(guān)文章

  • 在ASP.NET中連接SQL Server的簡單方法

    在ASP.NET中連接SQL Server的簡單方法

    在ASP.NET中訪問SQL Server數(shù)據(jù)庫有兩種方法,它們是System.Data.OleDb和System.Data.SqlClient.下面這段程序以System.Data.SqlClient為例訪問本地數(shù)據(jù)庫服務(wù)器.
    2013-04-04
  • Jexus部署.Net Core項目

    Jexus部署.Net Core項目

    這篇文章主要為大家詳細(xì)介紹了Jexus部署.Net Core項目的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • asp.net實現(xiàn)將ppt文檔轉(zhuǎn)換成pdf的方法

    asp.net實現(xiàn)將ppt文檔轉(zhuǎn)換成pdf的方法

    這篇文章主要介紹了asp.net實現(xiàn)將ppt文檔轉(zhuǎn)換成pdf的方法,通過自定義函數(shù)實現(xiàn)將pptx格式的文件轉(zhuǎn)換成pdf格式文件的功能,是非常實用的技巧,需要的朋友可以參考下
    2014-11-11
  • ASP.net如何連接SQL SERVER 2012數(shù)據(jù)庫

    ASP.net如何連接SQL SERVER 2012數(shù)據(jù)庫

    這篇文章主要介紹了ASP.net連接SQL SERVER 2012數(shù)據(jù)庫的方法,非常不錯,在項目開發(fā)中經(jīng)??梢杂玫?,需要的朋友可以參考下
    2016-08-08
  • 如何將數(shù)據(jù)綁到gridview然后導(dǎo)成excel

    如何將數(shù)據(jù)綁到gridview然后導(dǎo)成excel

    這篇文章主要介紹了如何將數(shù)據(jù)綁到gridview然后導(dǎo)成excel,需要的朋友可以參考下
    2014-02-02
  • asp.net中在用ajax格式傳遞數(shù)據(jù)到aspx頁面時出現(xiàn)亂碼

    asp.net中在用ajax格式傳遞數(shù)據(jù)到aspx頁面時出現(xiàn)亂碼

    asp.net中在用ajax格式傳遞數(shù)據(jù)到aspx頁面時有時會出現(xiàn)亂碼,很是疑惑,不要走開接下來介紹解決方法,感興趣的朋友可以了解下
    2013-01-01
  • asp.net core多文件分塊同時上傳組件使用詳解

    asp.net core多文件分塊同時上傳組件使用詳解

    這篇文章主要為大家介紹了一個可多個文件同時上傳、斷點續(xù)傳,并實時反饋上傳進(jìn)度的 Asp.Net core 組件,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-12-12
  • .NET 6開發(fā)TodoList應(yīng)用之實現(xiàn)查詢分頁

    .NET 6開發(fā)TodoList應(yīng)用之實現(xiàn)查詢分頁

    這篇文章介紹了.NET 6開發(fā)TodoList應(yīng)用之實現(xiàn)查詢分頁,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-01-01
  • .NET使用MailKit進(jìn)行郵件處理的方法步驟

    .NET使用MailKit進(jìn)行郵件處理的方法步驟

    這篇文章主要介紹了.NET使用MailKit進(jìn)行郵件處理的方法步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-02-02
  • ASP.NET Core MVC在視圖中使用依賴注入

    ASP.NET Core MVC在視圖中使用依賴注入

    這篇文章介紹了ASP.NET Core MVC在視圖中使用依賴注入的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-04-04

最新評論