I have an AJAX call that updates a $_SESSION
variable, after that the <script>
should echo out the new variable. The data is reaching the .php page, and also is being stored into the session. But it's alerting the old data after the AJAX call.
I've tried using setTimeout
and also tried moving the call that alerts the new variable outside of the AJAX
success call. I still get the same result.
Why isn't it alerting the new $_SESSION
data?
AJAX
<script>
$(function() {
$('#sendBtn').click(function() {
var theva = $("#element_23").val();
$.ajax({
type : "POST",
url :'check.php',
data : {theva : theva},
success: function() {
setTimeout(function() {
var theva2 = "<? echo $_SESSION['disp'];?>";
alert(theva2);},3000);}
});
});
});
</script>
check.php
<?
if($_POST){
$_SESSION['disp'] = $_POST['theva'];}
?>