C.Azzeddine
C.Azzeddine

Reputation: 25

I have some problems with reloading page in AJAX success function

Please help me i need to reload page after successful member login.
This is my code but nothing changes (page doesn't reload).
Note: I am using Laravel 5.4

    $.ajax({
                url: 'json/login',
                type: "POST",
                data : {
                        'email' : $("#connection :input[name='email']").val(),
                        'pwd' : $("#connection :input[name='pwd']").val(),
                        '_token' : $('meta[name="_token"]').attr('content')
                },
                dataType : "json",
                success: function(data,statusText,xhr){
                    if(data.success == 'ok'){
                         $(document).ajaxStop(function() { location.reload(true); });
                    }else{
                        $("#alert_danger").html(data.message);
                        $("#alert_danger").slideDown(100).delay(2000).slideUp(100);
                        $("#alert_success").slideUp(100);

                    }

                }
        });
    return false;
});

Upvotes: 0

Views: 211

Answers (2)

Vishnu
Vishnu

Reputation: 137

try window.location.reload(); This might work

Upvotes: 0

Max08
Max08

Reputation: 1025

I think you should just do this :-

if(data.success == 'ok'){
     location.reload(true);
}

Using $(document).ajaxStop does not make sense since you are already in the success function.

Upvotes: 1

Related Questions