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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:53:55+00:00 2026-06-09T08:53:55+00:00

From JavaScript, I’m calling a controller via AJAX like so: $.ajax({ type: ‘GET’, url:

  • 0

From JavaScript, I’m calling a controller via AJAX like so:

$.ajax({
  type: 'GET',
  url: '/books'
}

In my controller I have:

def index
  render 'lightbox.js.erb'
end

In my routes I have:

resources :books do
  member do
    get :lightbox
  end
end

In lighbox.js.erb I have:

alert("Hello world!");

For some reason, the alert is never getting called. I don’t get any error messages, either through the server or through Firebug. I’m at a loss for what could be going wrong. Any 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-06-09T08:53:56+00:00Added an answer on June 9, 2026 at 8:53 am

    It turns out that on the client-side, my JavaScript was being rendered as text. I confirmed this by looking at the console feed. It said:

    Started GET "/books/lightbox?book=4&username=tbaron&_=1344009191129" for 127.0.0.1 at 2012-08-03 10:53:11 -0500
    Processing by BooksController#lightbox as text
    

    Those last two words should have read “as JS.” After rooting around, I found this blog post which led to a surprisingly simple solution. Add “dataType: script” to the AJAX call:

    $.ajax({
      type: 'GET',
      url: '/books'
      dataType : 'script'
    }
    

    Thanks for your help, everyone!

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

Sidebar

Related Questions

I send data from javascript to PHP like this: $.ajax({'url': 'my.php', 'type': 'POST', 'data':
Possible Duplicate: Calling Python from JavaScript I have a test.py and test.js . I
Possible Duplicate: calling ASP function from javascript okay running this code : <script type=text/javascript>
Follow on from: Javascript wait for image to load before calling Ajax function initResources()
I'm calling PageMethod SameMethod from javascript method caller so that I can get some
I have been making calls to php from javascript with the jquery $.ajax({}). I
Need some help from javascript gurus. I have one page where http://www.google.com/finance/converter is embedded
I have a javascript interface class to receive some values from javascript. I toasted
I am trying to call c# function from javascript the code i have tried
I am trying to call a WebMethod from JavaScript. So far I have: The

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.