tags:

views:

437

answers:

3

I need to delaying the reloading of the page. Right now, I have this:

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

This obviously doesn't work. Anyone have an idea how to delay the reloading for atleast 3 seconds or so?

+1  A: 

setTimeout should do the job,

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

                        setTimeout( function() 
                        {
                          window.location = '<?php echo current_url();?>';
                        }, 3000);
                    });
                });
Artem Barger
I just had to edit the delay function and it worked :P sorry but I can only choose one.
Thorpe Obazee
+2  A: 
Ed Woodcock
+2  A: 

Use setTimeout to execute a function after a certain period:

$('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);               
                });
            });
Ikke
You got it! thanks man.
Thorpe Obazee