简体   繁体   中英

Specify spinner while loading content with Rails UJS

I'm using Rails UJS to load partials into a container depending on the link I click. I've got everything working (see my answer to my question here for code) but I'd like to add a spinner while the content is loading. How can I go about doing this? I found a brief example in Simone Carletti's post on UJS but can't seem to implement it properly.

Here's the HTML generated:

<div id="tabs">
  <ul id="infoContainer">
    <li><a href="/profiles/1/profile_reviews" class="active" data-remote="true" id="profile_loader">Reviews</a></li>
    <li><a href="/profiles/1/profile_about" class="inactive" data-remote="true" id="profile_loader">About</a></li>
    <li><a href="/profiles/1/profile_credits" class="inactive" data-remote="true" id="profile_loader">Credits</a></li>
    <li><span id="loading">Loading...</span></li>
  </ul>
  <div id="tabs-1">
    # load data from partials here
  </div>
</div>

Can anyone help me out?

See this SO answer for more info , but the easiest thing to do is to bind to the ajax:before and ajax:after events to show/hide the spinner.

Whether to do this via the javascript_event_tag or by binding in an external JS file is a different issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM