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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:18:30+00:00 2026-06-06T10:18:30+00:00

I need to pass a variable which is captured from client side via jquery

  • 0

I need to pass a variable which is captured from client side via jquery to controller, so that it can be used in the server side. After googling a bit, I found that we can pass it via an Ajax call.

routes.rb

get "mymethod?Id=", :to => "sample#mymethod"

j1.js

$(function(){

var test = 1;

$(.btn).click(function(){

  $.ajax({
           url: '/mymethod?Id='+ test,
           success: function(data) {
                 }
         });
    });

});

sample_controller.rb

def mymethod
 session[:Id] = params["Id"];
end

When I try to use session[:Id], it is always nil.

Any ideas,

Thanks

  • 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-06T10:18:33+00:00Added an answer on June 6, 2026 at 10:18 am

    If you want to make a GET request in jquery you’d be better off doing:

    $.ajax({
        url: '/mymethod',
        success: function(data){ // anything },
        data: { Id: test }
    });
    

    Because it urlencode and format the parameters correctly for you.

    In rails, remove the reference to the Id in routes.rb and just use the params dictionary in your controller to access the variable Id (info here: http://rails.nuvvo.com/lesson/6371-action-controller-parameters)

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

Sidebar

Related Questions

I need help on how to pass a variable from a jQuery click function
I am trying to call Ajax with jQuery and need to pass a variable
I need to pass an extra parameter :mobilejs => true from jQuery to a
I've a javascript variable which i need to pass as a parameter to the
I need to pass a variable from Admin.java file to index.jsp. I get the
I need to pass an instance variable (self.rank) to be used by a class
How to pass variable between two functions in same controller? Do I need to
I have session key that is a JavaScript variable which I got from a
Hey i have a situation in which i need to pass some variable value
In Java, there is ThreadLocal, which can be used to carry some data from

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.