1

I am trying to implement the solution as outlined in this post but can't get it to work.

application.js

$(document).ready(function(){
    $.ajaxSetup({
      beforeSend:function(){
          $('#loading').show();
        },
      complete:function(){
          $('#loading').hide();
        }
    });
});

application.html.erb

  <div id="loading" style="display:none;"><img src="/img/ajax-loader-circle.gif" ></br></br>Please wait...</div>

From my form, I added :remote => true and I could tell that an AJAX call was made looking at Rails logs. However, beforeSend show never got triggered. Thoughts?

Community
  • 1
  • 1
Bob
  • 8,424
  • 17
  • 72
  • 110

1 Answers1

2

I would recommend using:

$('#loading').ajaxStart(function(){
  $(this).show();
}).ajaxStop(function(){
  $(this).hide();
});

or if you want it for a particular form ID:

$('#someFormID')
.ajaxStart(function() {
    $('#loading').show();
})
.ajaxStop(function() {
    $('#loading').hide();
});

Make sure it's wrapped in a DOM ready block (like you've done). These are both working examples from one of my apps.

iwasrobbed
  • 46,496
  • 21
  • 150
  • 195