jQuery jquery自动刷新而不闪烁

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13324432/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 12:30:34  来源:igfitidea点击:

jquery auto refresh without blinking

jqueryrefresh

提问by Ivo

<script type="text/javascript">
window.onload = setupRefresh;

function setupRefresh() {
  setTimeout("refreshPage();", 1000);
}
function refreshPage() {
   window.location = location.href;
}

The page is now reloading every second the only problem its blinking how to fix this

该页面现在每秒重新加载,唯一的问题是闪烁 如何解决此问题

回答by Robbert Grobben

You could use a div and a .get with jquery to get your data from another page on your website.

您可以使用带有 jquery 的 div 和 .get 从您网站上的另一个页面获取数据。

You can use setTimeOut(function, time)

您可以使用 setTimeOut(function, time)

$(function() {
    startRefresh();
});

function startRefresh() {
    setTimeout(startRefresh,1000);
    $.get('pagelink.php', function(data) {
        $('#content_div_id').html(data);    
    });
}

回答by William Entriken

If the page is completely reloading and overwriting itself (including the script that is doing the reloading, then try this version:

如果页面完全重新加载并覆盖自身(包括正在重新加载的脚本,请尝试此版本:

function startRefresh() {
    $.get('', function(data) {
        $(document.body).html(data);    
    });
}
$(function() {
    setTimeout(startRefresh,1000);
});

回答by Francois

You can't reload a page that way without the blink effect. Have a look at AJAX to fetch updated content of the page and display it asynchronously in the "existing" page.

如果没有闪烁效果,您就无法以这种方式重新加载页面。看看 AJAX 来获取页面的更新内容并在“现有”页面中异步显示它。

Have a look at: http://www.brightcherry.co.uk/scribbles/jquery-auto-refresh-div-every-x-seconds/, to refresh part of the screen (the part can be the unique <DIV>of the page).

看看:http: //www.brightcherry.co.uk/scribbles/jquery-auto-refresh-div-every-x-seconds/,刷新屏幕的一部分(这部分可以是<DIV>页面的唯一)。

回答by Mareg

Thanks for answer with function, but if I want use about 1 minute delay, I must start calling of function with the delay by this way:

感谢您对函数的回答,但如果我想使用大约 1 分钟的延迟,我必须通过这种方式开始延迟调用函数:

<script type="text/javascript">
//<![CDATA[
var vTimeOut;

$(function() {
  vTimeOut= setTimeout(startRefresh, 60000)
});


function startRefresh() {
  clearInterval(vTimeOut);
  vTimeOut= setTimeout(startRefresh, 60000);
  $(<#div>).load(<loadURL>);
}

//]]>
</script>

Otherwise, the startRefresh functions fire very quickly or repeated more times.

否则, startRefresh 函数会非常快速地触发或重复多次。