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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:24:09+00:00 2026-05-22T02:24:09+00:00

when an user click on my display link, it goes to my display page,

  • 0

when an user click on my display link, it goes to my display page, a javascript runs after the page load and render the display. something like below:

...
display_data_hash = {}

function display() {
// use display_data_hash here
}
...

is it possible to populate “display_data_hash” in my javascript on the server side? or should i just add tag to my view and populate display_data_hash inside my html. i really don’t want mix javascript with html.

  • 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-22T02:24:10+00:00Added an answer on May 22, 2026 at 2:24 am

    First approach using AJAX

    you could retrieve your display_data_hash using AJAX (jQuery here) like:

    $.getJSON('/yourcontroller/youraction.json', function(data) {
    
       display(data);
    
    });
    

    and in your controller you render a json response like:

    class YourController < ApplicationController
       def your_display_action
    
          @my_data = .....
    
          respond_to do |format|
            format.json{ render :json => @my_data }
          end
       end
    end
    

    Second Approach without AJAX

    If you don’t want to fire an AJAX request you could do something like:

    In your layout view add a section:

    <html>
    <head>
    ....
    <script type="text/javascript">
        <%= yield :inline_js %>
    </script>
    ....
    </head>
    <body>
    ....
    </body>
    </html>
    

    then create a helper method like:

    def insert_display_data(display_data) {
    
      # convert hash to json
      data_json = display_data.to_json
    
      content_for :inline_js do
         "display('#{data_json}');"
      end
    }
    

    and in your display JavaScript function do:

    function display(data) {
    
      if(data instanceof String) { 
         // parse JSON using jquery
         data = $.parseJSON(data);
      }
    
      // your code...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When a user click a link, it would redirect them to a page, something
i have a command link in my page which looks like: <h:commandLink value=Add user
When the user click on Camera, it open next screen after few seconds it
I have done like if user click on the Button then the Sound is
i have created Array of Linkbutton and when user click on link button it
I want to display a facebox link when I click on a element when
How can I display an alert or a message after a user clicks a
I want after click on link show alert box with tow option ok and
I have to give user an email which will contain a link . After
I want to display a Sheet and when user clicks OK, show another sheet.

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.