濮阳杆衣贸易有限公司

主頁 > 知識庫 > .NET的Ajax請求數(shù)據(jù)提交實例

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

熱門標(biāo)簽:河北網(wǎng)絡(luò)回?fù)芡夂粝到y(tǒng) 河南語音外呼系統(tǒng)公司 外呼電銷機器人軟件 寧夏機器人電銷 400免費電話怎么辦理 400電話辦理最優(yōu)質(zhì) 威海電銷 t3出行地圖標(biāo)注怎么做 關(guān)于宗地圖標(biāo)注技術(shù)規(guī)范

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

復(fù)制代碼 代碼如下:
%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPagedynamic>" %> 
 
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="用戶名/手機號" 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è)計有所幫助。

您可能感興趣的文章:
  • JS Ajax請求如何防止重復(fù)提交
  • AJAX避免用戶重復(fù)提交請求實現(xiàn)方案
  • Ajax異步(請求)提交類 支持跨域
  • 按鈕的Ajax請求時一次點擊兩次提交的解決方法

標(biāo)簽:樂山 固原 賀州 廣元 咸寧 池州 吉林 淮北

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《.NET的Ajax請求數(shù)據(jù)提交實例》,本文關(guān)鍵詞  .NET,的,Ajax,請求,數(shù)據(jù),提交,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《.NET的Ajax請求數(shù)據(jù)提交實例》相關(guān)的同類信息!
  • 本頁收集關(guān)于.NET的Ajax請求數(shù)據(jù)提交實例的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    皮山县| 福泉市| 尼木县| 东丽区| 荃湾区| 墨江| 通榆县| 台州市| 肥城市| 郓城县| 彩票| 太康县| 和顺县| 辰溪县| 嘉峪关市| 阳谷县| 贞丰县| 文登市| 监利县| 蒙自县| 曲麻莱县| 余干县| 新化县| 涟源市| 金堂县| 淳化县| 武强县| 顺平县| 皋兰县| 成安县| 银川市| 雅江县| 乐至县| 武冈市| 三明市| 皮山县| 上饶县| 贡觉县| 呼玛县| 新丰县| 吉首市|