Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8893007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:08:40+00:00 2026-06-14T23:08:40+00:00

I’m trying to do a single post using coffeescript and jquery, but my script

  • 0

I’m trying to do a single post using coffeescript and jquery, but my script is not handling the success callback.

*cards_controller.js.coffee*

if $('form').attr('action') == '/cards'   alert "Hey ho"   $('#add_card').click (e) ->
    e.preventDefault()
    $.ajax '/cards',
      type: 'PUT' #Tried POST also
      dataType: 'json'
      error: (jqXHR, textStatus, errorThrown) ->
        console.log textStatus
      success: (res) ->
        console.log "Card name: " + data.card.code + "\nPoints: " + data.points
      complete: (jqXHR, textStatus) ->
        console.log "Status: " + textStatus

index.html.erb

<%= form_tag url_for(:controller => 'cards', :action => 'create'), :remote => true %>

And the generated javascript is the following one:

(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 > tbody:last').append('<tr>test</tr><tr>uauauiua</tr>');
        },
        complete: function(jqXHR, textStatus) {
          return console.log("Status: " + textStatus);
        }
      });
    });
  }

}).call(this);

*cards_controller.rb*

def create
    card = Card.find_by_code(params[:code])

    if card && card.user.nil?
      current_user.add_card(card)
    else
      return render :status => 401, :json => { :message => "O cartão não existe ou já está cadastrado"}
    end      

    respond_to do |format|
        format.js { render json: { :card => card, :points => card.card_business_points.sum("points") } , content_type: 'text/json' }
    end
end

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.

Please can someone help e with this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:08:41+00:00Added an answer on June 14, 2026 at 11:08 pm

    I just figured out what was the problem.

    In my coffeescript while doing the submit with jQuery ajax function I forget to add the data field with the content I want to submit.

    The final script is similar to this one:

    (document).ready ->
        if $('form').attr('action') == '/cards'
            $('#add_card').click (e) ->
                e.preventDefault()
                $.ajax '/cards',
                    type: 'POST'
                    dataType: 'json'
                    data: { code: $("#code").val() }
                    error: (jqXHR, textStatus, errorThrown) ->
                        alert textStatus
                    success: (data, textStatus, jqXHR) ->
                        console.log "Card name: " +
                                    data.card.code + "\nPoints: " + data.points
    

    Thank you for the help, I could not figure out why my callbacks were not being called when I did not passed the data parameter.

    Regards!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
I am reading a book about Javascript and jQuery and using one of the
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.