开发者

show loading dialog on AJAX request

开发者 https://www.devze.com 2023-04-13 05:33 出处:网络
In my Grails application, I would like to show some kind of visual indicator (possibly a modal dialog) when an AJAX request is in progress.

In my Grails application, I would like to show some kind of visual indicator (possibly a modal dialog) when an AJAX request is in progress.

I use JQuery for all my AJAX requests, currently they are all triggered using Grails tags, but I expect I'll eventually need to use the JQuery functions directly (e.g.$.ajax).

Is there some way I make this loading dialog appear/disappear each time an 开发者_StackOverflow社区AJAX requesting is starts/completes without having to repeat the code in every place I make an AJAX call?


$("#loading_animation").bind({
    ajaxStart: function() { $(this).show(); },
    ajaxStop: function() {  $(this).hide(); }
});


If it were me, I would switch over to explicitly using jquery. With jQuery, you can configure settings that all ajax requests will use

$.ajaxSetup({
   beforeSend: function(xhr, settings) {
     // do mask here
   },
   complete: function(xhr,textStatus){
     // remove mask here
   }

});

I found all this here.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号