Error using funtion in a new function [closed]

When I’m trying use function like sleep(2) in a new function I wrote, it’s not working.

function deleterow(id){
    $.post( "taskpost.php", { "deleteid": id, "delete":true } );
    sleep(1);
    $('#taskslist').load('taskslist.php').fadeIn('slow');
};

Answer

Have you coded sleep function or are you using it from some other library?

If you want to wait for the post request to complete try using this:

$.post("taskpost.php", { "deleteid": id, "delete":true } )
.done(function(data){
        $('#taskslist').load('taskslist.php').fadeIn('slow');
});

If you still want to delay it somewhat you can use setTimeout inside done callback.

Leave a Reply

Your email address will not be published. Required fields are marked *