How to implement a jQuery spinner image in an AJAX request

后端 未结 4 2109
無奈伤痛
無奈伤痛 2021-01-04 12:16

I have an jQuery AJAX request which I want to have display an ajax spinner gif while the request loads and then disappear once the request is successful, can anyone suggest

4条回答
  •  庸人自扰
    2021-01-04 12:44

    var $loading = $('#loadingDiv').hide();
    $(document)
      .ajaxStart(function () {
        $loading.show();
      })
      .ajaxStop(function () {
        $loading.hide();
      });
    

    where '#loadingDiv' is the spinner gif covering the part of the page or the complete page.

提交回复
热议问题