Eddie D.
Eddie D.

Reputation: 145

refresh page after ajax

i need to refresh the iframe after upload ajax about 2 seconds after it shows loading div but i can't set timeout for ajaxstop function

is there any way to do this?

$('form').ajaxForm({
        beforeSend: function() {
            status.empty();
            var percentVal = '0%';
        },
        uploadProgress: function(event, position, total, percentComplete) {
            var percentVal = percentComplete + '%';
            $("#progressbar").progressbar({
                value: percentComplete
            });
            $('#porcentagem').html(percentVal);
            if(percentComplete == 100){
                $('#wait').remove();

            }
        },
        complete: function() {
            setTimeout(function(){
                $('#conteudo_upload').hide();
                $('#loading').show(); 
            }, 800);

    setTimeout(function(){
        $(document).ajaxStop(function(){
            window.location.reload();
        }); 
    }, 1000);          
            } 
        });

Upvotes: 1

Views: 8045

Answers (2)

Dhaval Bharadva
Dhaval Bharadva

Reputation: 3083

try this:

$('form').ajaxForm({
    beforeSend: function() {
        status.empty();
        var percentVal = '0%';
    },
    uploadProgress: function(event, position, total, percentComplete) {
        var percentVal = percentComplete + '%';
        $("#progressbar").progressbar({
            value: percentComplete
        });
        $('#porcentagem').html(percentVal);
        if(percentComplete == 100){
            $('#wait').remove();

        }
    },
    complete: function() {
        setTimeout(function(){
            $('#conteudo_upload').hide();
            $('#loading').show(); 
        }, 800);

        setTimeout(function(){
               window.location.reload();
        }, 1000);          
    } 
});

Upvotes: 1

BadgerPriest
BadgerPriest

Reputation: 733

If you want to wait 1 second after all AJAX events complete, then you should change

setTimeout(function(){
    $(document).ajaxStop(function(){
        window.location.reload();
    }); 
}, 1000);  

to

$(document).ajaxStop(function(){
    setTimeout(function(){
        window.location.reload();
    }, 1000);
});

Upvotes: 2

Related Questions