ajax后刷新页面

时间:2013-07-23 06:35:05

标签: javascript jquery ajax

我需要在显示加载div后大约2秒后上传ajax后刷新iframe 但是我无法为ajaxstop函数设置超时

有没有办法做到这一点?

$('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);          
            } 
        });

2 个答案:

答案 0 :(得分:2)

如果你想在所有AJAX事件完成后等待1秒,那么你应该改变

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

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

答案 1 :(得分:1)

试试这个:

$('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);          
    } 
});