我希望页面上的一个 DIV 在 10 分钟后自动刷新。我不想重新加载整个页面,只想重新加载一部分。
这是我正在使用的 PHP:
function fblikes() {
$pageID = $_GET['id'];
$pagename = json_decode(file_get_contents('http://graph.facebook.com/' . $pageID));
echo $pagelikes->likes;
}
这就是我想要自动刷新的内容:
<div>
<span><?php fblikes(); ?></span>
</div>
有人可以帮我解决这个问题吗?
最佳答案
You cannot 'reload a div'. A
div
is just a single element on an entire webpage, and on its own it has no URL it was loaded from, so it cannot be reloaded. You can set/replace the contents of a div with an Ajax call, but that's definitely not 'reloading' - you'd need to explicitly define the URL to load its new content from.
您需要编写一些 Javascript,使用 setTimeout
安排函数在 10 分钟内执行,然后使用 Ajax 调用检索 JSON 或 HTML 数据,然后将其解析或放入相关的 span
元素。
在您的具体情况下,您可以通过使用 Facebook 客户端 Javascript API 让自己的生活更轻松,并且只需每 10 分钟发出一次 FB.api(...)
调用,因为这似乎成为你想要的。
关于php - 10分钟后自动刷新DIV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16618719/