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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:36:19+00:00 2026-06-15T16:36:19+00:00

In my controller action i initialize a session of array and inserting values. These

  • 0

In my controller action i initialize a session of array and inserting values. These values are coming from the client side through ajax, so the page is not refreshed while inserting these values to an array.But suprisingly every time it iniatialize a new session instead of inserting to the same defined session. Here is my code

controller

def receive_tags
  parser = Yajl::Parser.new
  @hash = parser.parse(request.body.read)
  log=Logger.new(STDOUT)
  log.error(@hash)
  session[:tags]||=[]
  session[:tags] << @hash["tag"]
    unless session[:tags].empty?
    log.error(session[:tags] ) #this keeps printing the current value i was expecting it to print a list of values including the previous
    end
  render :nothing=>true
 end

Ajax

 var myobj={tag:"mytag"};
 $.ajax({
    url: 'ips/receive_tags',
    type: 'post',
    contentType: 'application/json; charset=UTF-8',
    accept: 'application/json',
    dataType: 'json',
    data:JSON.stringify(myobj),
    success: function(res) {
        if (res.ImportResponse !== void 0) {
            console.log('Success: ' + res);
        } else if (res.Fault !== void 0) {
            console.log('Fault: ' + res);
        }
    },
    error: function() {
        console.error('error!!!!');
    }
});
  • 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-15T16:36:21+00:00Added an answer on June 15, 2026 at 4:36 pm

    Finally i figured it out, The problem is i wasn’t setting the request header for the token before sending ajax call so Rails was receiving data without the token, thus kept assuming it is a new object for every request.You can read more here.To set the request header add

      beforeSend: function(xhr) {
    xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'));
     }
    

    Below is my ajax function that works

    var myobj={tag:"mytag"};
    $.ajax({
    url: 'ips/receive_tags',
    type: 'post',
    contentType: 'application/json; charset=UTF-8',
    accept: 'application/json',
    dataType: 'json',
    data:JSON.stringify(myobj),
     beforeSend: function(xhr) {
    xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'));
     }
     success: function(res) {
        if (res.ImportResponse !== void 0) {
            console.log('Success: ' + res);
        } else if (res.Fault !== void 0) {
            console.log('Fault: ' + res);
        }
     },
     error: function() {
        console.error('error!!!!');
     }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My Controller Action accepts int id. What to do when calling from View ActionLink
So if your Controller Action returns a Model with pre-populated values, how do you
class AboutController extends Zend_Controller_Action { public function init() { /* Initialize action controller here
Hello I am trying to retrieve the values ​​returned by a controller action in
In my Controller Action I set Cookie with Response.SetCookie(myCookie) method. In my Unit Test
I have the following controller action: [HttpGet] public JsonpResult getTestValues(int? entityId, int? id) {
I have a custom controller action as listed below. I have a form with
Zend recommends to put controller action helpers in the mvc into /application/controllers/helpers . Is
I have a controller action that checks this.User.Identity.IsAuthenticated What do you suggest how to
I have a POST controller action like: if (ModelState.IsValid) { try { //.. save

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.