html页
<form >
<input type="text" id="userID" name="userID" placeholder="卡号" />
<input type="password" id="userPwd" name="userPwd" placeholder="密码" />
<input type="button" id="btn_login" value="登陆" />
</form>
JS代码
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#btn_login").click(function () {
$.ajax({
url: "/Login/UserLogin",
type: "post",
data: $("form").serialize(),
dataType: "html",
success: function(data) {
var serverData = data.split(':');
if (serverData[0] == "OK") {
window.location.href = "Home/Index";
} else if (serverData[0] == "NO") {
alert("密码错误!");
$("#erorrmessage").text(serverData[1]);
} else {
window.location.href = "~/Views/Shared/Error.cshtml";
}
}
})
});
})
</script>
LoginController控制器
public ActionResult UserLogin()
{
string username = Request["userID"].ToString();
string userpassword = Request["userPwd"].ToString();
CRPJCGL.BLL.UserInfoService userinfoservice = new CRPJCGL.BLL.UserInfoService();
if (userinfoservice.SelectTeacherId(username) == true)
{
if (userinfoservice.GetTeacherModel(username, userpassword) != null)
{
return Content("OK:登陆成功");
}
else
{
return Content("NO:密码错误");
}
}
else
{
return Content("NO:卡号错误!");
}
}
|