10分钟后自动刷新DIV [英] Auto-refresh DIV after 10 minutes
问题描述
我希望我的网页上有一个DIV在10分钟后自动刷新。我不想重新加载整个页面,只是一部分。
I would like one DIV on my page to automatically refresh after 10 minutes. I don't want to reload the entire page, just the one part.
这是我使用的PHP:
function fblikes() {
$pageID = $_GET['id'];
$pagename = json_decode(file_get_contents('http://graph.facebook.com/' . $pageID));
echo $pagelikes->likes;
}
这就是我想要自动刷新的内容:
And this is what I want to be refreshed automatically:
<div>
<span><?php fblikes(); ?></span>
</div>
有人可以帮我吗?
Can somebody help me with this please?
推荐答案
引用自己:
您无法'重新加载div'。一个
div
只是一个
整个网页上的单个元素,并且它本身没有它加载的URL,所以它
不能是重新加载。您可以使用
Ajax调用设置/替换div的内容,但这绝对不是重新加载 - 您需要
明确定义要从中加载其新内容的URL。
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
分钟,然后使用Ajax调用来检索JSON或HTML数据,然后将其解析或放入相关的 span
元素中。
You need to write some Javascript, use setTimeout
to schedule a function for execution in 10 minutes, and then use an Ajax call to retrieve JSON or HTML data that is then either parsed or placed in the relevant span
element.
在您特定的情况下,您可以通过使用Facebook客户端Javascript API来让自己的生活更轻松,只需发出 FB.api(...)
打电话每10分钟一次,因为这似乎是你想要的。
In your very specific situation you can make your own life easier by using the Facebook clientside Javascript API, and just issue a FB.api(...)
call every 10 minutes since that appears to be what you want.
这篇关于10分钟后自动刷新DIV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!