简体   繁体   English

每x秒刷新一次DIV内容而没有永恒页面吗?

[英]Refresh DIV contents every x seconds WITHOUT eternal page?

Here's an example: 这是一个例子:

<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('#photos').load('photos.php').fadeIn("slow");
}, 5000); // refresh every 10000 milliseconds
</script>

<div id="photos"></div>

The problem is the complexity of the other javascript on the page isn't really ideally for reloading the div from an external page. 问题是页面上其他javascript的复杂性并不是从外部页面重新加载div的理想选择。 If it's the only way, I'll backtrack and work that out... I was just wondering if it's possible to refresh the div contents from the page itself? 如果这是唯一的方法,我将回溯并解决……我只是想知道是否有可能从页面本身刷新div内容?

You can read the whole page, then extract the element you're looking for: 您可以阅读整个页面,然后提取要查找的元素:

$('#photos').load('YourPage.php#photos');

The server will still send the entire page to the client. 服务器仍将整个页面发送给客户端。

function refreshDiv(){
    $('#photos').load('photos.php').fadeIn("slow");
    setTimeout("do_again()", 5000)
}

function do_again(){
    refreshDiv();
}

That would keep loading your jQuery every 5 seconds (5000ms). 那将保持每5秒(5000毫秒)加载一次jQuery。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM