• MVC登录



    @{
    Layout = null;
    }

    <!DOCTYPE html>

    <html>
    <head>
    <meta name="viewport" content="width=device-width" />
    <title>LoginIndex</title>
    <link href="~/Content/bootstrap.css" rel="stylesheet" />
    <script src="~/Scripts/jquery-3.4.1.js"></script>
    <script>
    //文档加载函数
    $(function () {
    if (getCookie("UsersInfo") == null) {
    setCookie("UsersInfo", "[]");
    }
    else {
    var list = JSON.parse(getCookie("UsersInfo"));
    var obj = {
    ACount: list[0].ACount,
    Pwd: list[0].Pwd
    }
    Aj(obj);
    }
    })
    function Login() {
    var obj = {
    ACount: $("#ACount").val(),
    Pwd: $("#Pwd").val(),
    }
    Aj(obj);

    }
    function Aj(obj) {
    $.ajax({
    url: "http://localhost:57190/api/Sale/Login",
    data: obj,
    type: "get",
    dataType: "json",
    success: function (d) {
    if (d != null) {
    var list = JSON.parse(getCookie("UsersInfo"));
    var st = {
    ACount: $("#ACount").val(),
    Pwd: $("#Pwd").val(), UId: d.UId
    };
    list.push(st);
    var data = JSON.stringify(list);
    setCookie("UsersInfo", data);
    alert('登录成功');
    location.href = '/Sale/OrdersInfoIndex?UId=' + d.UId;
    }
    else {
    alert('账号或密码输入错误');
    }
    }
    })
    }


    /* cookie中存值
    */
    function setCookie(name, value) {
    if (value) {
    var days = 1; //定义一天
    var exp = new Date();
    exp.setTime(exp.getTime() + days * 24 * 60 * 60 * 1000);
    // 写入Cookie, toGMTString将时间转换成字符串
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString;
    }
    };

    /**
    * cookie中取值
    * */
    function getCookie(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); //匹配字段
    if (arr = document.cookie.match(reg)) {
    return unescape(arr[2]);
    } else {
    return null;
    }
    };
    </script>
    </head>
    <body>

    <table class="table" style="margin:0 auto;85%;height:85%;text-align:center">
    <tr>
    <td>账号:</td>
    <td><input id="ACount" type="text" placeholder="请输入您的账号" /></td>
    </tr>
    <tr>
    <td>密码:</td>
    <td><input id="Pwd" type="password" placeholder="请输入您的密码" /></td>
    </tr>
    <tr>
    <td colspan="2"><input id="Button1" type="button" value="登录" onclick="Login()" /></td>
    </tr>
    </table>
    </body>
    </html>

  • 相关阅读:
    第三次作业
    Mysql show variables系统变量详解
    利用正则检测文中敏感词并标红
    Android 连接大疆SDK
    Android 热修复方案Tinker
    Hander消息机制
    .net MemCache 入门到简单使用链接汇总
    用socket连接pop3服务器遇到的小问题
    我是如何取得Reflector的真实程序的
    google卫星地图的url计算
  • 原文地址:https://www.cnblogs.com/zhang0405/p/13275499.html
Copyright © 2020-2023  润新知