title: rails 4 ajax event not triggering success
body: <p>I'm working on my rails 4 demo app, and I've got a button that is meant to do some work on the server side, then return <code>json</code> with a success or failure message.</p>
  
  <p>Similar to <a href="https://stackoverflow.com/questions/19918193/rails-4-ajaxsuccess-isnt-being-triggered">this</a> question, I am seeing the response come back with a 200 code and the expected <code>json</code> payload, but the jQuery success event is not triggered-- to make it more confusing, it seems to be somewhat intermittent-- sometimes I get the proper action (showing a flash message and removing a div) but most of the time nothing happens.</p>
  
  <p>Here's the button in the view:</p>
  
  <pre><code>&lt;%= link_to 'Do Work', widget_path(:id =&gt; widget.id), id: widget.id, remote: true, method: :get %&gt;
  </code></pre>
  
  <p>Here's the controller:</p>
  
  <pre><code>respond_to do |format|
    if widget.save
      // this json is returned properly
      format.json { render json: { status: 'success', msg: 'Widget created.', :content_type =&gt; 'text/json', type: 'info', item: 'widget' } }
    else
      format.json { render json: @user.errors, :content_type =&gt; 'text/json', status: :unprocessable_entity }
    end
  end
  </code></pre>
  
  <p>The javascript in <code>application.js</code>:</p>
  
  <pre><code>var fade_flash = function() {
      $("#flash_success").delay(2000).fadeOut("slow");
      $("#flash_info").delay(2000).fadeOut("slow");
      $("#flash_warning").delay(2000).fadeOut("slow");
      $("#flash_danger").delay(2000).fadeOut("slow");
  };
  fade_flash();
  
  var show_ajax_message = function(msg, type) {
      $("#notice").html('&lt;div id="flash_'+type+'" class="alert alert-dismissable alert-'+type+'"&gt;&lt;button type="button" class="close" data-dismiss="alert" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;'+msg+'&lt;/div&gt;');
      fade_flash();
  };
  </code></pre>
  
  <p>Here's the coffeescript in <code>widget.js.coffee</code>:</p>
  
  <pre><code>$ -&gt;
    $("a[data-remote]").on "ajax:success", (e, data, status, xhr) -&gt;
      alert('got here')
      console.dir(data)
      if data.status == 'success' 
          show_ajax_message(data.msg, data.type) 
          if data.item == 'widget'
              $('#widget_'+this.id).hide('slow')
  </code></pre>