开发者

How to display an activity loader automatically with all ajax requests?

开发者 https://www.devze.com 2022-12-29 04:09 出处:网络
I am working on Ruby on Rails application, with Prototype. I want to display a loading div automaticallywith every ajax request and hide it on completion, without writing code for every ajax request i

I am working on Ruby on Rails application, with Prototype. I want to display a loading div automatically with every ajax request and hide it on completion, without writing code for every ajax request in my application. Is there anyway to do this.

<div开发者_JS百科 id="loader">Loading...</div>


You may want to check out this article:

  • Automatic Ajax Loading Images With Prototype by Ben Kittrell

Basically you can handle it with:

  Ajax.Responders.register({
     onCreate : startLoading,
     onComplete : stopLoading
  });

Where startLoading and stopLoading are callback functions that show/hide your activity indicator.


I can't tell you how to do this in Prototype, but I once implemented something similar in Dojo: The trick was to extend the "xhrGet"-method which was responsible for AJAX-requests. Doing that I had my own methods that would start on the request and handle the "done"-event where I could show/hide a loader.

I assume you can extend methods in Prototype so this may get you started.

0

精彩评论

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

关注公众号