Implement a loading indicator for a jQuery AJAX call

前端 未结 6 1393
我在风中等你
我在风中等你 2020-12-04 05:54

I have a Bootstrap modal which is launched from a link. For about 3 seconds it just sits there blank, while the AJAX query fetches the data from the database. How can I impl

6条回答
  •  时光取名叫无心
    2020-12-04 06:12

    I solved the same problem following this example:

    This example uses the jQuery JavaScript library.

    First, create an Ajax icon using the AjaxLoad site.
    Then add the following to your HTML :

    
    

    And the following to your CSS file:

    #loading-indicator {
      position: absolute;
      left: 10px;
      top: 10px;
    }
    

    Lastly, you need to hook into the Ajax events that jQuery provides; one event handler for when the Ajax request begins, and one for when it ends:

    $(document).ajaxSend(function(event, request, settings) {
        $('#loading-indicator').show();
    });
    
    $(document).ajaxComplete(function(event, request, settings) {
        $('#loading-indicator').hide();
    });
    

    This solution is from the following link. How to display an animated icon during Ajax request processing

提交回复
热议问题