ASP.NET MVC 表单submit()

时间:2022-01-31 04:52:59

HTML代码

            <form id="frmLogin">
                <div class="form-group has-feedback">
                    <input type="text" class="form-control" placeholder="账户" id="user">
                    <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
                </div>
                <div class="form-group has-feedback">
                    <input type="password" class="form-control" placeholder="密码" id="password">
                    <span class="glyphicon glyphicon-lock form-control-feedback"></span>
                </div>
                <div class="row">
                    <!-- /.col -->
                    <div class="col-xs-12">
                        <button type="submit" class="btn btn-primary btn-block btn-flat">登录</button>
                    </div>
                    <!-- /.col -->
                </div>
            </form>

JS代码

          $("#frmLogin").submit(function (e) {
                $.ajax({
                    type: 'Post',
                    dataType: 'text',
                    url: '/sysUser/verification',
                    async: false,
                    data: { user: $("#user").val(), password: $("#password").val() },
                    //登录成功:success,登录失败error
                    success: function (result) {
                        if (result == "success") {
                            alert("用户名或密码正确!");
                            //location.href = "/main/i";
                        }
                        else
                        {
                            alert("用户名或密码错误!");
                        }
                    }
                });
            });