Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2012
    Posts
    282
    Plugin Contributions
    0

    Default creating a $_SESSION var w/ AJAX, and jQuery, but is disappearing on subsequent pages

    Yesterday i coded a form checkbox to set a PHP Session variable on tpl_shopping_cart_default.php. i used jQuery and Ajax to do so. below is the code.

    the problem is that the variable $_SESSION['hm-agreement'], is disappearing on subsequent pages, like for ex: tpl_shopping_cart_default, or log-in etc. i do a var_dump($_SESSION) to check this.

    in the code below i've even echoed out the the SESSION var in a callback function via a js alert and it is echoing back correctly.

    PHP Code:
    $(document).ready(function(){
        $(
    'input:checkbox').click(function(){
            if(
    this.checked) {
                
    state 'checked';
            } else {
                
    state 'unchecked';
            }
            $.
    get('pyro-agreement.php', {action:state}, function(data) {alert(data); })
        }); }) 
    am hesitant to supply a link to the dev. site here but could do so privately.
    i did a little study to test the code in a simpler environment and seems to be working as expected.

    http://tomcarden.net.previewdns.com/...tudy/intro.php

    any help on this would be appreciated. i don't understand why the variable once created doesn't exist on sub-sequent pages. i've

  2. #2
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: creating a $_SESSION var w/ AJAX, and jQuery, but is disappearing on subsequent p

    If your ajax script hasn't started the *same* session that your live page is using, then none of its variables will carry over.

    Simpler would be to have your javascript set the HTML for the corresponding input field on your actual page, and then have that normal page (nothing to do with ajax) submit that field with all the rest of its submission data, and parse it just like all the other input fields on the page, and have it set the session variable from there.
    example: the checkout-comments field or the checkout terms-and-conditions field.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

 

 

Similar Threads

  1. jQuery AJAX Manufacturer Filter
    By rbarbour in forum General Questions
    Replies: 4
    Last Post: 31 Dec 2013, 08:42 PM
  2. v151 jQuery ajax with type POST and securityToken
    By pasi in forum Contribution-Writing Guidelines
    Replies: 2
    Last Post: 26 Mar 2013, 10:38 AM
  3. v139h I want to add 2 var in $_SESSION
    By linjuming in forum General Questions
    Replies: 3
    Last Post: 26 May 2012, 10:59 AM
  4. Replies: 1
    Last Post: 21 Apr 2010, 06:37 PM
  5. jQuery to Ajax: how to call application_top.php?
    By joomoo79 in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 10 Mar 2010, 09:07 AM

Posting Permissions

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