如何刷新DIV内容? [英] How do I refresh a DIV content?
问题描述
<div id='here'></div>
我试图在一堆div中刷新某个div。除了在XMLHttpRequest的帮助下发送的许多变量之外,div内容基本上由PHP以及来自MySQL数据库的数据生成。
I am trying to refresh a certain div within a bunch of divs. The div content is basically generated by PHP along with data from a MySQL database in addition to many variables being sent with the help of an XMLHttpRequest.
想法是重新加载/刷新div本身而不是加载php文件或用 .text
或 .html
。在这种情况下,我不能使用 .load('file.php')
The idea is to reload/refresh the div itself and not load a php file or to overwrite it with .text
or .html
. In this case, I cannot use .load('file.php')
我尝试过:
<script type='text/javascript'>
function updateDiv()
{
document.getElementById("here").innerHTML = document.getElementById("here").innerHTML ;
}
</script>
和(每3秒刷新一次):
and (for a every 3 second refresh) :
$(document).ready(function () {
setInterval(function () {
$('#here').load('#here'));
}, 3000);
});
理想情况下,我需要以下内容:
Ideally, I would require something like :
function reloadDIV () {document.getElementById("here").innerHTML.reload}
function reloadDIV () {$('#here').load(self)}
以便我可以在onClick中使用它:
so that I can use it in a onClick :
<a onclick='reloadDIV ();'>reload div</a>
推荐答案
要重新加载页面的一部分,您可以使用jquerys 使用当前url加载
并指定所需的片段,这与调用 load
的元素相同,在这种情况下 #here
:
To reload a section of the page, you could use jquerys load
with the current url and specify the fragment you need, which would be the same element that load
is called on, in this case #here
:
function updateDiv()
{
$( "#here" ).load(window.location.href + " #here" );
}
此功能可以在一个间隔内调用,也可以附加到点击事件
This function can be called within an interval, or attached to a click event
这篇关于如何刷新DIV内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!