MVC登录页面
@{
ViewBag.Title = "DengL";
}
<h2>DengL</h2>
<script src="~/Scripts/jquery-3.3.1.js"></script>
<script src="~/Scripts/bootstrap.js"></script>
<link href="~/Scripts/bootstrap.css" rel="stylesheet" />
<table class="table table-bordered">
<tr>
<td>用户名:</td>
<td><input id="User" type="text" /></td>
</tr>
<tr>
<td>密码:</td>
<td><input id="Pwd" type="text" /></td>
</tr>
<tr>
<td></td>
<td><input id="dl" type="button" value="登录" class="btn btn-primary" onclick="pr()" /></td>
</tr>
</table>
<script>
function pr() {
var obj = {
username: $("#User").val(),
pwd: $("#Pwd").val()
}
$.ajax({
url: 'http://localhost:7202/api/Default/DengLu',
type: 'get',
data: obj,
dataType: 'json',
success: function (d) {
if (d != null) {
Scookir();
location.href = "http://localhost:8691/Default/Order";
}
else {
alert('账户或密码错误')
}
}
})
}
function Scookir() {
if (getCookie('user') == null) {
setCookie("user", "");
}
var usernamestr = getCookie('user');
var username = JSON.parse(usernamestr);
username = $("#User").val();
setCookie("user", JSON.stringify(username));
}
/**
* 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>
浙公网安备 33010602011771号