A
A
Ayk722015-11-09 23:51:15
JavaScript
Ayk72, 2015-11-09 23:51:15

How to make a function load in 3 seconds?

Good evening!
How to make the startLoadingAnimation() function work for 3 seconds, and then the response from the server comes?

$(document).ready(function(){
    var $form = $('#filter'),
        $controls = $form.find('input,select,textarea');

    $controls.on('change', function(){
         startLoadingAnimation();
        $.post("url", $("#filter").serialize(), function(response){
           
           $('#dle-content').html(response); stopLoadingAnimation();
    });
             });
});
         
 function startLoadingAnimation() 
{
   $("#dle-content").append('<div id="res"><img src="http://katushka.in.ua/templates/katushka2/images/ajax-loader.gif" /></div>');
}
          
function stopLoadingAnimation() 
{
   $("#res").remove();
}

Thanks in advance!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Skogorev, 2015-11-09
@EnterSandman

setTimeout()

T
twobomb, 2015-11-09
@twobomb

setTimeout(function(){
    //Ответ 
},3000)

S
Serdji, 2015-11-10
@ssumatokhin

function interval () {
    
    var inteval= setInterval( function (){
      //body....
    }, 100 ); // долбит каждые 100 м/ск 

    setTimeout( function (){
      clearInterval( intevalt );
    }, 3000 ); // останавливаем интервал через 3 ск
  };
interval (); // запускаем функцию

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question