Automatically update $ _SESSION variables without updating

I am using the $ _SESSION variable to send emails via AJAX (they need to be sent without refreshing the page), but the $ _SESSION variable is not automatically updated, so when it changes I need to refresh the page before updating the variable.

Is it possible to update the $ _SESSION variable without updating?

This is the code I am using to send email:

$(document).ready(function(){
    $("#medicalembassy").validate({
        debug: false,
        rules: {
            name: "required",
            email: {
                required: true,
                email: true
            }
        },
        messages: {
            name: "Please let us know who you are.",
            email: "",
        },
        submitHandler: function(form) {
            // do other stuff for a valid form
            $.post('http://www.example.co.uk/erc/process.php?imei=<?php echo $_SESSION['imei2']; ?>&send_type=2', $("#medicalembassy").serialize(), function(data) {
                $('#results').html(data);
            });
        }
    });
});

      

This way, if the $ _SESSION variable changes, I need this AJAX email to recognize it without having to update.

Thanks for any help

+2


source to share


2 answers


The variable A $ _SESSION is obtained by running "session_start ();" and cleared if you use "session_destroy ();". However, you cannot get changes in session variables multiple times in the same document: the document that requests AJAX will see the changes in $ _SESSION every time that page was requested (a page inside AJAX).



+3


source


Make your PHP script return JSON containing both the html results and the new value from the session. Then, on a successful callback, you update whatever needs to be updated with the session value.



0


source







All Articles