取消Button.Click通过Jquery执行操作 [英] Cancel Button.Click action through Jquery

查看:78
本文介绍了取消Button.Click通过Jquery执行操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试创建一个小型登录屏幕。我没有使用任何API。我设置登录界面的方式如下:

1.用户在VIEW中输入登录名和密码。

2.用户点击登录按钮

3.我通过ajax验证用户详细信息。

4.在此阶段,如果细节正确,我将用户转移到下一页。

5.如果详情是正确的我只是输入错误信息。



这是我得到的JQuery代码。

Hi I am trying to create a small login screen. I am not using any API. The way I have set up the login screen is as follow
1. user enter login name and password in VIEW.
2. user clicks login button
3. I validate user details through ajax.
4. At this stage if details are correct, I transfer user to the next page.
5. If details are correct I just put in error message.

Here is the JQuery code I got.

$(document).ready(function () {
    var returnType;
    $("#loginButton").click(function () {
        var loginDetails = {
            loginName: $("#username").val(),
            password: $("#password").val()
        };
        $.ajax({
            url: '@Url.Action("VerifyLoginDetails", "Home")',
            type: 'POST',
            contentType: 'application/json',
            dataType: 'json',
            data: JSON.stringify(loginDetails),
            success: function (data) {
                if (data.success) {
                    if (data.loginAuthentication == 1) {
                        return true;
                    }

                    if (data.loginAuthentication == -2) {
                        $("#password").attr("style", "display:block;");
                        alert("incorrect password");
                        return false;
                    }

                    if (data.loginAuthentication == -1) {
                        $("#username").attr("style", "display:block;");
                        alert("incorrect un");
                        return false;
                    }

                }
            }
        });
    });
});





据我所知,如果我返回true,它不应该向控制器发送呼叫但由于某种原因它仍然。任何建议如何通过JQUERY停止对控制器的调用。



As far as my knowledge is concerned that if I return true it should not send call to controller but for some reason it still does. any suggestions how can I stop the call to controller through JQUERY.

推荐答案

document )。ready( function (){
var returnType;
(document).ready(function () { var returnType;


#loginButton)。click( function (){
var loginDetails = {
loginName:
("#loginButton").click(function () { var loginDetails = { loginName:


#username)。val(),
密码:
("#username").val(), password:


这篇关于取消Button.Click通过Jquery执行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆