.net MVC 用jquery读取表单数据,AJAX异步提交表单例子

论坛 期权论坛 脚本     
匿名技术用户   2021-1-3 22:23   11   0

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:卡号错误!");
}

}
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP