Search code examples
ruby-on-railsujs

Rails 3 UJS unexpected behavior


I have such a form:

<form id="new-application" method="post" enctype="multipart/form-data" data-remote="true" action="/inv/claims?locale=uk" accept-charset="UTF-8">
<a rel="nofollow" data-remote="true" data-method="delete" data-confirm="Are You sure?" href="/inv/claims/1?locale=uk">delete</a> 
<a rel="nofollow" data-remote="true" data-method="delete" data-confirm="Are You sure?" href="/inv/claims/2?locale=uk">delete</a> 
</form>

Also I have in my.js such lines of code:

var toggleLoading = function() { $("#ajax-loader").toggle() };

$("#new-application")
    .bind("ajax:loading",  alert('loading'))
    .bind("ajax:complete", alert('complete'))
    .bind("ajax:success", function(event, data, status, xhr) {
      alert('succ');
    });

When I click on delete I only get a message succ but I am waiting for a message loading and after that a message succ.

Why Doesn't I get a message loading before succ?


Solution

  • I found this.

    Hope it helps.

    Here is the URL:

    http://tesoriere.com/2011/05/19/rails-3.1-%26%238212%3B-fixing-the-'ajax-loading'-event/