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

  • Home
  • SEARCH
  • 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 8826325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:06:31+00:00 2026-06-14T07:06:31+00:00

As I mentioned in a question last week, I’m working with @coreyward ‘s excellent

  • 0

As I mentioned in a question last week, I’m working with @coreyward‘s excellent walk-through for modal edit windows in Rails 3. However, I’m a relative novice with Coffeescript, and I’m having trouble with the code which is supposed to display the modal window on a successful Ajax response. This is the relevant function (drawn from Corey’s gist):

$ ->
  $modal = $('#modal')
  $modal_close = $modal.find('.close')
  $modal_container = $('#modal-container')

  # Handle modal links with the data-remote attribute
  $(document).on 'ajax:success', 'a[data-remote]', (xhr, data, status) ->
    $modal
      .html(data)
      .prepend($modal_close)
      .css('top', $(window).scrollTop() + 40)
      .show()
    $modal_container.show();

  $(document).on 'click', '#modal .close', ->
    $modal_container.hide()
    $modal.hide()
    false

I’ve established that all the code inside the function works; it just never gets called. I can see the Ajax query in the Chrome network panel, and verify that it returns a proper response.

I simplified the code to pop up an alert on an ajax:success event:

  $(document).on 'ajax:success', () -> 
    alert('Ajax success event!')

…and nothing. So I think the `ajax:success’ event is never happening.

Trying to extract the simplest possible code that duplicates the problem, I set up this jsFiddle with the following code:

<a href="javascript:$.ajax('/echo/js/?delay=2&js=WHEEEEE!');" data-remote="true">Edit</a>​

$(document).on 'ajax:success', () -> 
  alert('Ajax success event!')

​
…yeah. Nothing. The jsFiddle Ajax echo returns what it should, but the function never gets called. So I’m doing something wrong with .on('ajax:success'). (This is sort of the opposite problem as this question, so that answer isn’t helpful. This question, about the mime-type of the response, looks promising, but doesn’t explain why the jsFiddle doesn’t work, because that doesn’t touch my controllers.) What is it?

ETA: I should probably mention the stack involved here. facepalm

  • Rails 3.2.8
  • jquery-rails 2.1.3
  • …which means jQuery 1.8.2
  • 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-14T07:06:32+00:00Added an answer on June 14, 2026 at 7:06 am

    OK, got it. I needed to make two changes:

    • First, as suggested by this answer, I needed to be returning a text/json MIME type on the response. My action previously looked like this:
      def edit
        respond_to do |format|
          format.js
          format.html
        end
      end
    

    To get a text/json response I wound up with this:

      def edit
        respond_to do |format|
          format.js { render :json => { :html => render_to_string('edit')}, :content_type => 'text/json' }
          format.html
        end
      end
    

    That change triggered ajax:success and therefore ran the open-modal functions.

    • However, because the response payload was now in data.html rather than just data, I needed to tweak the modal.js.coffee to actually put markup in the modal:
      .html(data.html) // instead of .html(data)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've asked very similar question before and should have mentioned more detailed. Last time
So based on this question ( here ), of which I asked last week,
--edit -- Solved the question : a comment on the last sidenote would be
I previously asked a question about fetching the last 100 mentions for a person
From the link ( which is mentioned in Question ) my question is that
The question is mostly related to PHP because IMHO opcode is mostly mentioned in
In this question , I mentioned my assumption that rubyforge gems are more official,
As I mentioned in a recent question on how to show strings with carriage
As i mentioned in a previous question I'm fairly new to the world of
In an answer to another question it was mentioned that passing XML as a

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.