每次登录时,我都会从MySQL数据库中获取$_SESSION[balance]的值。如何在不每5分钟重新加载页面的情况下更新客户端浏览器中的值?我认为使用AJAX可以做到这一点?
抱歉,如果这太含糊了,我完全不知道从哪里开始。
发布于 2012-04-21 19:23:55
你是对的,你需要AJAX来做这件事。最简单的方法是在jQuery library中使用$.get();
js/jQuery脚本
window.setInterval(function() {
$.get('script.php', function(balance) {
$('#balance').html(balance); // set the value to the element with the ID balance
});
}, 60000); // execute every minute在script.php中,您只需查询数据库中的余额并回显即可
https://stackoverflow.com/questions/10258411
复制相似问题