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

1 篇文章 0 订阅
1 篇文章 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:卡号错误!");
            }
           
        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值