title: My ajax post with coffeescript is not handling success callback
body: <p>I'm trying to do a single post using coffeescript and jquery, but my script is not handling the success callback.</p>
  
  <p>*cards_controller.js.coffee*</p>
  
  <pre><code>if $('form').attr('action') == '/cards'   alert "Hey ho"   $('#add_card').click (e) -&gt;
      e.preventDefault()
      $.ajax '/cards',
        type: 'PUT' #Tried POST also
        dataType: 'json'
        error: (jqXHR, textStatus, errorThrown) -&gt;
          console.log textStatus
        success: (res) -&gt;
          console.log "Card name: " + data.card.code + "\nPoints: " + data.points
        complete: (jqXHR, textStatus) -&gt;
          console.log "Status: " + textStatus
  </code></pre>
  
  <p><em>index.html.erb</em></p>
  
  <pre><code>&lt;%= form_tag url_for(:controller =&gt; 'cards', :action =&gt; 'create'), :remote =&gt; true %&gt;
  </code></pre>
  
  <p>And the generated javascript is the following one:</p>
  
  <pre><code>(function() {
  
    if ($('form').attr('action') === '/cards') {
      alert("Hey ho");
      $('#add_card').click(function(e) {
        e.preventDefault();
        return $.ajax('/cards', {
          type: 'POST',
          dataType: 'json',
          error: function(jqXHR, textStatus, errorThrown) {
            return alert(textStatus);
          },
          success: function(res) {
            console.log("Card name: " + data.card.code + "\nPoints: " + data.points);
            return $('#card-list &gt; tbody:last').append('&lt;tr&gt;test&lt;/tr&gt;&lt;tr&gt;uauauiua&lt;/tr&gt;');
          },
          complete: function(jqXHR, textStatus) {
            return console.log("Status: " + textStatus);
          }
        });
      });
    }
  
  }).call(this);
  </code></pre>
  
  <p>*cards_controller.rb*</p>
  
  <pre><code>def create
      card = Card.find_by_code(params[:code])
  
      if card &amp;&amp; card.user.nil?
        current_user.add_card(card)
      else
        return render :status =&gt; 401, :json =&gt; { :message =&gt; "O cartão não existe ou já está cadastrado"}
      end      
  
      respond_to do |format|
          format.js { render json: { :card =&gt; card, :points =&gt; card.card_business_points.sum("points") } , content_type: 'text/json' }
      end
  end
  </code></pre>
  
  <p>The request goes successfuly to the controller and the card is created correctly. The problem is that debugging on the Chrome it seems that it don't handle with the callback and don't log.</p>
  
  <p>Please can someone help e with this?</p>