SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Aug 2009
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Rails session across jquery ajax call

    Hey Guys,

    Kind of a strange problem, hopefully someone can help me out.

    I want to set a session in my rails controller which I hit via jquery ajax get.

    $.get('/leads/check', function(data) {console.log(data);});

    which hits the controller action

    def check
    session[:tester] = "test"
    end

    The session doesnt seem to be set across the ajax call and the js console gave back
    "Failed to load resource: the server responded with a status of 500 (Internal Server Error)"

    Checking the rails logs also verifys that the controller check action is hit..

    Anyone have an ideas on this?

    Cheers,

    Stuart

  2. #2
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sessions rely on an identifier (session id) being transmitted in cookies with each http request. By default, xhr won't transmit the browsers cookies. You need to pass the session id manually.

    What are you using session for in this case? There's probably a better solution (Like passing the shared data in some inline javascript).


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •