weixin_33735077 2015-11-08 23:40 采纳率: 0%
浏览 19

Ajax事件仅工作一次

when i enter the wrong details and run it. it pops up with the error message, but if i then enter the correct details and click run it again. the sign in button changes to "Connecting..." as it should but then nothing else happens

$(document).ready(function() {

    var width = ( $(".main").width() - 5);
    if (width < 300) {
        $(".logo-img").css({"width":width});
    };

    $("#error").hide();

    $(function() {
        $('#login').on('click', function(e){
            e.preventDefault();

            var token = $('#token').val();
            var username = $('#username').val();
            var password = $('#password').val();
            var remember = $('#remember:checked').val();

            $.ajax({
                url: 'core/functions/ajaxLogin.php',
                method: 'POST',
                data: { 'username' : username,
                        'password' : password, 
                        'remember' : remember, 
                        'token' : token },
                dataType: 'html',
                cache: false,
                beforeSend: function() { $('#login').val('Connecting...') },
                success: function( data ) {
                    if (data == 'success') {
                        setTimeout( "window.location.href='backorderbook';", 500 );
                    } else if( data == 'userorpass' ) {
                        $('#error').fadeIn();
                        $('#error_message')
                           .html('username or password were entered incorrectly');
                        $('#error').delay(3500).fadeOut();
                        $('#login').val('Sign In');
                    };
                }
            });
        });
    });
});
  • 写回答

3条回答 默认 最新

  • 游.程 2015-11-08 23:46
    关注

    run your function with Fiddler .. and/or add the error parameter to your ajax... odds are your web request isn't a success.

    评论

报告相同问题?