Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax jQuery stalling

Tags:

jquery

ajax

I'm fairly new to jQuery. I've written this script that manages an ajax request for a login.

My problem is sometimes the script sometimes does not execute anything from if (data == "success") (or any other login response) if I log in and out a few times.

It stalls at $.post("exec_login.php") even though it ran through the code previously with no problems without reloading the page.

$(document).ready(function() {

    //HTTP AJAX LOGIN REQUEST
    $("#modal_login_button_existing_user").click(function(){

        $.post("exec_login.php",
        {
            email : $("#modal_login_existing_email").val(),
            password : $("#modal_login_existing_password").val()
        },
        function(data,status){
            if (data == "success")
            {
                $('#modal_login_alert_success').html('').append('<strong>Welcome!</strong> You are now successfully logged in.').fadeIn(1000).delay(2000).queue(function(){ 
                    $('.session_hide').hide();
                    $('#modal_login').modal('hide').delay(1000).queue(function(){ 
                        $('.session_show').show();
                        $('.session_fadein').fadeIn(2000);
                        $('.session_opacity').css({opacity: 1}).show();

                        //$('.logged_in_name').html('').append(first + ' ' + second).show();
                    });
                });
            }
            else if (data == "failure")
            {   
                $('#modal_login_alert_success').hide();
                $('#modal_login_alert_failure').html('').append('<strong>Woops!</strong> The login details you provided were incorrect.').show();
            }
            else if (data == "empty")
            {
                $('#modal_login_alert_success').hide();
                $('#modal_login_alert_failure').html('').append('<strong>Darn!</strong> Some of the login boxes are empty still.').show();
            }
        });
    }); 
});

and log out code:

$(document).ready(function() {  

    //HTTP AJAX LOGOUT REQUEST
    $("#modal_logout_button").click(function(){
        alert("test");
        $.post("exec_logout.php",
        {
            logout : "1",
        },
        function(data,status){
            if (data == "success")
            {
                $('.session_hide').fadeIn(1000).delay(200).queue(function(){
                    $('.session_show').hide();
                    $('.session_fadein').hide();
                    $('.session_opacity').hide();
                    $('#modal_logout').modal('hide');
                });
            }
        });
    }); 
});
like image 547
Amy Neville Avatar asked Jun 29 '26 13:06

Amy Neville


1 Answers

I took the approach of simplifying my script to the following for the success response. Unsprisingly working like a nicely oiled machine now, if a bit less of a flashy one.

        if (data == "success")
        {
            $('.session_hide').hide();
            $('#modal_login').modal('hide');
            $('.session_show').show();
            $('.session_fadein').fadeIn(2000);
            $('.session_opacity').css({opacity: 1}).show();
        }
like image 166
Amy Neville Avatar answered Jul 02 '26 02:07

Amy Neville