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('<?ph开发者_JAVA技巧p 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?
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);
});
});
The jQuery .delay method is only for delaying function chains, you want to use 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('reload()', 800);
});
});
function reload() { window.location = '<?php echo current_url();?>'; }
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);
});
});
Try this one, saves mixing php and jQuery, the "."
reloads the current page.
setTimeout(window.location = ".", 600);
精彩评论