最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Automatically update $_SESSION variables without refreshing - Stack Overflow

programmeradmin0浏览0评论

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.

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

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('.php?imei=<?php echo $_SESSION['imei2']; ?>&send_type=2', $("#medicalembassy").serialize(), function(data) {
                $('#results').html(data);
            });
        }
    });
});

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

Thanks for any help

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.

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

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);
            });
        }
    });
});

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

Thanks for any help

Share Improve this question asked May 11, 2011 at 11:28 Daniel HDaniel H 2,9258 gold badges36 silver badges32 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

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).

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

发布评论

评论列表(0)

  1. 暂无评论