So I have a number in the MYSQL table which is displayed on the screen using the function:
function getWinNumber($db) {
$user = getProfileInfoFor($_SESSION['id'], $db);
$winNumber = $user->number;
return $winNumber;
}
Then after some user actions that value changes in the DB and I want to update it in front-end when they close a foundation modal:
$(document).on('close.fndtn.reveal', '#ex6-4', function () {
$('.number').html("<?php echo getWinNumber($db);?>");
});
The problem is that even though the code works, and I can clearly see in the DB that the value has changed before I close the modal, the value being pulled is still the old one. Why is that?
If I put anything else in there like:
$(document).on('close.fndtn.reveal', '#ex6-4', function () {
$('.number').html("test");
});
it works. It updates when I close the modal.
I ended up doing it with AJAX like this and it worked:
$(document).on('close.fndtn.reveal', '#ex6-4', function () {
$.ajax({ url: 'include/update.php',
data: {action: 'update'},
type: 'post',
success: function(output) {
$('.encrypted').html(output);
}
});
});
and for the PHP:
if(isset($_POST['action']) && !empty($_POST['action'])) {
$action = $_POST['action'];
if ($action == 'update') {
echo getWinNumber($db);
}
}