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 badges2 Answers
Reset to default 3A $_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.