复制代码 代码如下:
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<head runat="server">
<title>ajax请求</title>
<link type="text/css" href="https://www.jb51.net/Content/style.css" />
<script type="text/javascript" src="https://www.jb51.net/Scripts/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="https://www.jb51.net/Scripts/js.js"></script>
</head>
<body>
<!--顶部+logo+导航-->
<div>
<div>
<a title="ajax请求">ajax请求</a></div>
</div>
<!---->
<div>
<div>
<img src="https://www.jb51.net/Images/4499633_182932517000_2.jpg" /></div>
<div>
<h2>
<span>会员登录</span><span>没有账号?<a href='<%=Url.Action("Register","Account") %>'>立即注册</a></span></h2>
<form>
<div>
<div>
<input type="text" value="用户名/手机号" />
</div>
<div>
<input type="text" value="密码" />
<input type="password" />
</div>
<div>用户名或密码错误!</div>
<div>
<label>
<input type="checkbox" checked />
自动登录</label>
<a href='<%=Url.Action("ResetPwd","Login") %>' >忘记密码?</a>
</div>
<input 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) {
//回传内容{status: 1(success)/0(fail),}
if (ajaxObj.status == 0 || status == null) {
$(".warn").show().html('用户名或密码错误!');
} else {
//登陆成功,跳转都制定页面
window.location = '/memberCenter/index';
}
}, "json");
});
});
</script>
</html>
控制器
复制代码 代码如下: