无刷新自动更新$ _SESSION变量变量、自动更新、_SESSION

2023-09-10 21:31:57 作者:谎言交织成了网

我使用的是$ _SESSION变量通过AJAX(他们需要在不刷新页面发送)发送电子邮件,但$ _SESSION变量不会自动更新,所以当它改变时,我需要刷新页面来更新变量

I am using a $_SESSION variable to send emails via AJAX (they need to be sent without refreshing the page), but the $_SESSION variable doesn't automatically update, so when it changes I need to refresh the page to update the variable.

是否有可能无刷新更新$ _SESSION变量?

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

这是在code我使用发送邮件:

This is the code I'm using to send the 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);
            });
        }
    });
});

因此​​,基本上,如果$ _SESSION变量的变化,我需要这个AJAX电子邮件认识到,无需刷新。

So basically, if the $_SESSION variable changes, I need this AJAX email to recognise that without having to refresh.

感谢您的帮助

推荐答案

一个$ _SESSION变量可以通过在session_start();和清除,如果你使用的session_destroy();。你不能在会话变量的变化多次在同一个文档,但是:文档的AJAX请求被请求的页面每次(AJAX的内页)将会看到的变化,$ _SESSION

A $_SESSION variable is obtained when you run "session_start();" and cleared if you use "session_destroy();". You cannot get the change in the session variables multiple times in the same document, however: the document your AJAX is requesting would see the changes in $_SESSION each time that page was requested (the page inside the AJAX).