使用jQuery延迟重新加载页面

Tee*_*eej 1 jquery delay

我需要延迟重新加载页面.现在,我有这个:

$('div.navigation_sorter ul li a.delete').click(function(event){
                event.preventDefault();
                var li = $(this).closest('li');
                $.post('<?php echo site_url('admin/navigation/delete_link');?>', { link: li.attr('id')}, function(data){
                    $('<div class="feedback info"><p>'+ data +' has been deleted</p></div>').insertAfter('.navigation_sorter').delay(800);
                    window.location = '<?php echo current_url();?>';
                });
            });
Run Code Online (Sandbox Code Playgroud)

这显然不起作用.任何人都知道如何延迟重新加载至少3秒左右?

Ikk*_*kke 15

使用setTimeout在一段时间后执行一个函数:

$('div.navigation_sorter ul li a.delete').click(function(event){
                event.preventDefault();
                var li = $(this).closest('li');
                $.post('<?php echo site_url('admin/navigation/delete_link');?>', { link: li.attr('id')}, function(data){
                    $('<div class="feedback info"><p>'+ data +' has been deleted</p></div>').insertAfter('.navigation_sorter')
                    setTimeout(function(){
                         window.location = '<?php echo current_url();?>';
                    }, 3000);               
                });
            });
Run Code Online (Sandbox Code Playgroud)