There is such a script

function submitFilter(){ form= $("form[name=filterForm]"); form.find("[name=page]").val(0); data= form.serialize(); $(".cap").css({display:"block"}); $.ajax({ type: 'POST', url: form.attr("action"), data: data, success: function(answer) { $(".blockContent").empty(); $(".blockContent").append(answer); $(".cap").css({display:"none"}); } }); } 

Between $ (". Cap"). Css ({display: "block"}); and $ (". cap"). css ({display: "none"}); it takes little time and I do not have time to see the loader. You can somehow set a timer or slow down for at least 1 second to see the loader.

  • Why do you need it? If data is loaded / processed quickly, then everything works fine, without brakes. - Visman
  • Well, there is more for the user to see that the data is loaded, otherwise he doesn’t even understand that there was a download - duddeniska
  • @duddeniska deliberately do the data loading longer, so that the user sees the loader, while everyone is fighting for speed - are you a pervert sir)) ..... and during social networks will you emulate a lot of database work too?) so that the page loads for two seconds ) - Alexey Shimansky

2 answers 2

 var timeout; function submitFilter(){ form= $("form[name=filterForm]"); form.find("[name=page]").val(0); data= form.serialize(); $(".cap").css({display:"block"}); $.ajax({ type: 'POST', url: form.attr("action"), data: data, success: function(answer) { $(".blockContent").empty(); $(".blockContent").append(answer); clearTimeout(timeout); timeout = setTimeout(function() { $(".cap").css({display:"none"}); }, 1000); } }); } 

    setTimeout - exactly what you need

     form= $("form[name=filterForm]"); form.find("[name=page]").val(0); data= form.serialize(); $(".cap").css({display:"block"}); setTimeout(function() { $.ajax({ type: 'POST', url: form.attr("action"), data: data, success: function(answer) { $(".blockContent").empty(); $(".blockContent").append(answer); $(".cap").css({display:"none"}); } }); }, 2000);