Show Preloader waiting for more than 500 ms



  • Standard bond request

    $("#load").click(function() {
        $.ajax({
            beforeSend: function (data) {
                $('#loading_box').show();
            },
            success: function (j) {
                $('#loading_box').hide();
                $('#content').html(j.html);
            }
        });
    
    return false;
    

    });

    I think so. beforeSend We need to show the load indicator inside. setTimeout
    But what if the event comes success with a surveillance team, and then it ends. timeout And the indicator will show up when you don't need it?

    Preloader needs to show up at the loading, longer than a certain time, and hide when the answer comes. In addition, it must be borne in mind that a reset of clicks and a request may not be successful. Obviously, in all these cases timeout shall be cleaned and re-established at the last request.

    Can you tell the algorithm or the example of the code? Or maybe there's something that's ready for such an advanced withdrawal?



  • $('button').click(function() {
        $.ajax({
            beforeSend: function (data) {
                timer = setTimeout(function() {
                    gif.show();
                }, 500);
            },
            complete: function() {
                clearTimeout(timer);
                gif.hide();
            },
        });
    });
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2