开发者

show loading dialog on AJAX request

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜