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 7496317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:33:54+00:00 2026-05-29T18:33:54+00:00

Here is a simple Tell a Friend form I made in HTML, it’s correctly

  • 0

Here is a simple Tell a Friend form I made in HTML, it’s correctly POSTING the data back to my server and submitting correctly.

Here’s the javascript code (it’s in CoffeeScript):

$('#tell-a-friend-form').submit (e) ->
    e.preventDefault()
    console.log "submitted form."

    $.ajax
      url: 'home/tellafriend'
      type: 'POST'  
      data:
        name: $(this).find("input[name='name']").val()
        emails: $(this).find("input[name='emails']").val()
        message: $(this).find("textarea[name='message']").val()
      success: (result) ->
        alert("ok")
        $('#tell-a-friend-form').find(".loading-icon").hide()
      error: (result) ->
        alert("Sorry, we couldn't send your message.")    
        $('#tell-a-friend-form').find(".loading-icon").hide()
        $('.tell-a-friend-submit').removeAttr("disabled")

    $(this).find(".tell-a-friend-submit").attr("disabled", "disabled")
    $(this).find(".loading-icon").show()

Now, in the Controller, I don’t need to return any message at all, except maybe a “sent ok” type of boolean so the client side javascript can know whether to “success” or to “error”.

Currently, the client side fires “error” every time.

Here’s my Controller code:

def tellafriend
  #send the actual email message. to be implemented.

  respond_to do |format|
    format.json { render :json => "success" }
  end
end

Anything I’m doing wrong on the controller side? I’m sure the problem lies here. What do I need to return in case I want the “success” bit to fire?

  • 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-05-29T18:33:54+00:00Added an answer on May 29, 2026 at 6:33 pm

    What do your logs show you when you make the request? This is important for diagnosing this sort of thing. There are three things I can think of that usually fix this:

    Explicitly Request JSON

    It might be as simple as explicitly requesting JSON from your AJAX call:

    $.ajax
      url: 'home/tellafriend'
      type: 'POST'
      dataType: 'json'
      ...
    

    Check Your Routes:

    Your route might not be configured to respond to POST requests. Ensure your route for ‘tellafriend’ accepts post. As a quick check you could change your AJAX request to ‘GET’ or visting /home/tellafriend.json

    Return a Valid Object

    Instead of simply returning “success” You might want to try returning an actual object:

    respond_to do |format|
      format.json { render :json => {:message => "success"} }
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a simple form I am using to send XML data in admin_xml.php
Here my simple accordion : <script type=text/javascript> $(function() { $(dt.title).click(function() { $(div.info).slideUp(slow); $(this).next(div.info:hidden).slideDown(normal );
So the question here is pretty simple: is there a way to tell if
my sample code is here include 'simple_html_dom.php'; function get_all_links($url){ global $host; $html = new
Hi i've got here a simple program, but it's not working properly. When i
Please excuse me if I'm simple here, I want to create a simple widget
I have to be missing something simple here but it escapes me. After the
I hope I am not missing something very simple here. I have done a
I think I'm just missing something simple here but here is what I am
Here is some simple code: DIR* pd = opendir(xxxx); struct dirent *cur; while (cur

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.