else语句不在ajax中工作

时间:2017-12-27 14:20:17

标签: javascript ajax

$(document).ready(function() { 

    $('#loginsubmit').click(function() { 
        var email = $('#email').val();  
        var password = $('#password').val(); 

        if (email != "" && password != "") { 
            $.ajax({
                type: "POST",
                url: "User_Actions/PHP_Actions/Login.php",
                data: "email=" + email + "&password=" + password,
                beforeSend: function() {
                    $('#loginsubmit').val("...");
                },
                success: function(data) {
                    $('#loginsubmit').val('Login');
                    if (data){
                        $('.error-login').html(data);
                        $('.news-login').html("");
                    } else {
                        alert("data");
                    }
                }
            });
        }
    });
});

IF语句正在运行,但是其他方法不起作用且没有控制台错误! 请解决它对我来说很重要! 它之前是工作但在我工作之后它又停止了工作

帮助帮助帮助帮助帮助帮助帮助帮助帮助帮助帮助帮助帮助帮助帮助帮助帮助帮助帮助帮助

1 个答案:

答案 0 :(得分:0)

尝试以这种方式添加错误处理:

$(document).ready(function() {

    $('#loginsubmit').click(function() { 
        var email = $('#email').val();  
        var password = $('#password').val(); 

        if (email != "" && password != "") { 
            $.ajax({
                type: "POST",
                url: "User_Actions/PHP_Actions/Login.php",
                data: "email=" + email + "&password=" + password,
                beforeSend: function() {
                    $('#loginsubmit').val("...");
                },
                success: function(data) {
                    $('#loginsubmit').val('Login');
                    $('.error-login').html(data);
                    $('.news-login').html("");
                },
                error: function( jqXhr, textStatus, errorThrown ){
                    console.log( errorThrown );
                }
            });
        }
    });
});