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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:28:26+00:00 2026-05-30T13:28:26+00:00

I’m trying to get some json from an action but I have a problem.

  • 0

I’m trying to get some json from an action but I have a problem.

I know that you can return “format.js” and return an “.js.erb” file but… Imagine I have an action that return some stuff and I want to work with that in two different ways. I cannot have that two different ways on the same .js.erb because when I return it, both ways will be executed, right? I mean, when I return that file, that file will be processed entirely.

So I tried to use the jQuery way.

I have:

# GET /posts/slug/hidden_content.json
def hidden_content
  @post = Post.find(params[:id])
  @post = hidden_post_part(@post.body)

  respond_to do |format|
    format.json { render json: @post, :status => :ok}
  end
end

And in the controller.coffee:

$ ->
  # Render hidden part of post
  $(".showallpost img").click( ->
    post_url = $(this).next().attr("href").split("/").pop();
    $.ajax
      url: Routes.hidden_content_path(post_url),
      type: "GET",
      contentType: "application/json",
      success: (data) ->
        console.log "foo"
  );

The GET works perfectly and it returns what I need but the success function is never called, I don’t see the “foo” log.

I guess that the action should return something to tell to the caller that the GET was successful. (I tried with :status without luck).

So I can’t work with my GET data.

Ideas?

  • 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-30T13:28:27+00:00Added an answer on May 30, 2026 at 1:28 pm

    Seems like my controller was returning plain html instead of json, so when I used

    dataType: 'json'
    

    I needed to use:

    dataType: 'html'
    

    Kinda weird, because it should return some json, but well, it works.

    All the thanks to Mike Johnson in: jquery doesn't call success method on $.ajax for rails standard REST DELETE answer

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
Does anyone know how can I replace this 2 symbol below from the string
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post

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.