[英]How to get data in Highstock from PHP MySQL data on AJAX call
[英]How to call php function to get updated data from MYSQL with jQuery
因此,我在使用函數顯示在屏幕上的MYSQL表中有一個數字:
function getWinNumber($db) {
$user = getProfileInfoFor($_SESSION['id'], $db);
$winNumber = $user->number;
return $winNumber;
}
然后,在執行一些用戶操作后,數據庫中的值發生了變化,當他們關閉基礎模式時,我想在前端對其進行更新:
$(document).on('close.fndtn.reveal', '#ex6-4', function () {
$('.number').html("<?php echo getWinNumber($db);?>");
});
問題是,即使代碼可以工作,並且我在數據庫中清楚地看到在關閉模式之前值已更改,但要拉取的值仍然是舊值。 這是為什么?
如果我在里面放其他東西:
$(document).on('close.fndtn.reveal', '#ex6-4', function () {
$('.number').html("test");
});
有用。 當我關閉模態時,它會更新。
我最終用這樣的AJAX進行了工作,並且成功了:
$(document).on('close.fndtn.reveal', '#ex6-4', function () {
$.ajax({ url: 'include/update.php',
data: {action: 'update'},
type: 'post',
success: function(output) {
$('.encrypted').html(output);
}
});
});
對於PHP:
if(isset($_POST['action']) && !empty($_POST['action'])) {
$action = $_POST['action'];
if ($action == 'update') {
echo getWinNumber($db);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.