Javascript 使用 jQuery 每 10 秒自动加载和刷新 Div

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3121285/
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-23 03:20:21  来源:igfitidea点击:

Auto Load and Refresh Div every 10 Seconds with jQuery

javascriptjquery

提问by Webby

I'm working with a nice little Jquery that auto loads and refreshes a div every bla bla Seconds. Works perfectly on all browsers then I load up IE and bang what a surprise no luck! :(

我正在使用一个漂亮的小 Jquery,它每隔 bla bla 秒自动加载和刷新一个 div。在所有浏览器上都能完美运行,然后我加载 IE 并砰的一声,没有运气!:(

Index.html

索引.html

<script  type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('#load').load('reload.php').fadeIn("slow");
}, 10000); // refresh every 10000 milliseconds

<body>
<div id="load"> </div>
</body>

</script>

reload.php

重新加载.php

<?

echo time(); //just a timestamp example..

?>

Any ideas guys?

有什么想法吗?

采纳答案by Teja Kantamneni

Add a random value at the end of the url to avoid caching.. That should solve your problem. ex: $('#load').load('reload.php?_=' +Math.random()).fadeIn("slow");

在 url 末尾添加一个随机值以避免缓存.. 这应该可以解决您的问题。前任:$('#load').load('reload.php?_=' +Math.random()).fadeIn("slow");

回答by Catfish

Try closing your script tag before having your body tag.

在拥有 body 标签之前尝试关闭您的脚本标签。

<head>
<script  type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('#load').load('reload.php').fadeIn("slow");
}, 10000); // refresh every 10000 milliseconds

</script>
</head>

<body>
<div id="load"> </div>
</body>

回答by Friyank

  body {text-align:center; background-image: url('http://cdn3.crunchify.com/wp- content/uploads/2013/03/Crunchify.bg_.300.png')}


    $(document).ready(function() {
        auto_refresh();
    });
    function auto_refresh(){
        var randomnumber = Math.floor(Math.random() * 100);
        $('#show').text('I am getting refreshed every 3 seconds..! Random Number ==> '+ randomnumber);
    }
    var refreshId = setInterval(auto_refresh, 1000);