title: Rails: How to catch ajax success
body: <p>I googled a lot and was unable to find my mistake. As I just started with JS this might be an easy one. Using: Rails 4</p>
  
  <p>I have a modal with a form that I would like to do stuff after successfully (or not) doing the ajax call. For now just closing the modal.</p>
  
  <p>modal (this works actually works, so I can edit stuff):</p>
  
  <pre><code>.modal.fade{ id: attribute.id, role: 'dialog', tabindex:'-1' }
    .modal-dialog{ role: 'document'}
      .modal-content
        .modal-header
          %button{ type: 'button', class: 'close', 'data-dismiss' =&gt; "modal" }
            %span &amp;times;
          %h4.modal-title= attribute.name
  
    = form_for attribute, remote: true, html: { class: 'form-inline', id: 'edit_form' } do |f|
      .modal-body
        .form-group
          = f.label :name, 'Name', class: 'form-label', style: 'width: 150px'
          = f.text_field :name, class: 'form-control', style: 'width:200px;margin-right: 35px'
      .modal-footer
        %button{ type: "button", class: "btn btn-default pull-left", 'data-dismiss' =&gt; "modal" }
          Close
        = f.submit 'Create', class: 'btn btn-primary pull-right'
  </code></pre>
  
  <p>my JS file (dont laugh):</p>
  
  <pre><code>$(document).ready( function($) {
          console.log('ready'); # this I *can* see in the console
  
      $('#edit_form').bind("ajax:success", function() {
        console.log('great success') # this I *can't* see in the console.
      });
  });
  </code></pre>
  
  <p>controller (additional fun fact: The modal is triggered in a view for a different controller, not the one of the modal that I am actually trying to change):</p>
  
  <pre><code>respond_to do |format|
    format.js {}
  end
  </code></pre>
  
  <p>So in the end I would like to catch the "error" and "success" callbacks and do sth with it (this I am trying to figure out myself first). What am I doing wrong here?</p>
  
  <p>Thanks a lot for your help - it is really appreciated!</p>