gpt4 book ai didi

php - 使用 jquery 每隔 X 秒从 phpfile 获取内容?

转载 作者:行者123 更新时间:2023-11-29 20:21:47 24 4
gpt4 key购买 nike

这可能吗?我需要从另一个 phpfile 中获取一些数据,我希望它每隔 X 秒出现一次,而无需刷新页面。

最佳答案

是的,它被称为 "polling" or "periodic refresh"

您可以使用setInterval(参见@Luca 的回答)和jQuery's ajax API与 PHP 文件通信,以及 jQuery 的 DOM 操作 API 来改变页面的内容。最简单的形式:

setInterval(function(){
$.get('ajax.php', function(data) {
$('.result').html(data);
alert('Load was performed.');
});
}, 5000); // 5 seconds

关于php - 使用 jquery 每隔 X 秒从 phpfile 获取内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3661314/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com