I want to delay jQuery ajax successful function

kilogram picture kilogram · Nov 27, 2016 · Viewed 7.3k times · Source

I want to let user wait for 2 seconds before the HTML inside the block changes. Can you help me to set some time so that ajax request was not so fast and I had time to show some animation

I tried to set timeout but it is not working

Answer

TheValyreanGroup picture TheValyreanGroup · Nov 27, 2016

Just use setTimeout in your success callback function.

success : function(data){
    setTimeout(function(){
         var newWidget = $(data); 
         $('#widget-container').replaceWith(newWidget);
     },2000);  // The millis to wait before executing this block
},