Organizational Research By

Surprising Reserch Topic

how to use jquery ajax post to store php session variables using -'php,jquery,ajax,forms,session'


how to use jquery ajax post to store php session variables  using -'php,jquery,ajax,forms,session'

Help!

I'm having trouble wrestling AJAX to work for me. I have a paginated gallery with checkboxes beneath each image and I need to store the checkbox values in session variables if a user moves between the pages, so when they submit the form at any time it will include all checked values across all pages.

I'm using this jQuery code:

$(document).ready(function() {
    $(".gal-nav").click(function() {
        $.post("form-data-holder.php", $("#gallery-form").serialize());
    });
});


and the form-data-holder.php file says this:

<?php

    $_SESSION['saved'] = "true";

    foreach ($_POST as $key=>$value ) {
        if ( $key !== "submit" ) {
            $value = htmlentities(stripslashes(strip_tags($value)));
            $_SESSION[$key] = $value;
        }
    }

?>


I have two issues --

1) How do I get the checkbox values out of the serialize() function? I think there's more I have to do with something like value[] to get that array out, and then I guess store each one as a separate session variable -- unless I can store an array as a $_SESSION variable?

2) Before I even mess with any of that, I added that line $_SESSION['saved'] = "true"; to the php script and then I echo the $_SESSION keys and values on my gallery page to see if the AJAX request is even working. It's not. That $_SESSION['saved'] isn't added to the list of echoed $_SESSION variables when I return to the page.

Any help would be greatly appreciated!!
    
asked Sep 7, 2015 by rajesh
0 votes
13 views



Related Hot Questions



Government Jobs Opening


...