简体   繁体   English

jQuery更新Div错误

[英]Jquery updating Div error

I have made this code: 我做了这段代码:

<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(){
        $('#main2').empty();
        $('#main2').load('index.php?_='+Math.random()+'    #main2').fadeIn("slow");
    }, 10000); // refresh every 10000 milliseconds
</script>

in the header. 在标题中。

My div: 我的div:

<div id="main2">
<?php include('newsong.php'); ?>
</div>

it updates but i can see the whole page flick(not the index.php), instead of only the div. 它更新,但我可以看到整个页面轻弹(不是index.php),而不仅仅是div。 I have searched, but nothing is like this question. 我已经搜索过,但是没有什么比这个问题更重要了。 Thank you. 谢谢。

After many tries i found the script that work, at least for me(firefox): 经过多次尝试,我发现了至少对我来说有用的脚本(firefox):

<script type="text/javascript"  src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
    <script type="text/javascript">
     $(document).ready(function() {
        $("#main2").load("newsong.php");
        var refreshId = setInterval(function() {
        $("#main2").load('newsong.php?randval='+ Math.random());
        }, 9000);
     });
    </script>

And for the div: 对于div:

<div id="main2">
<noscript>
<?php
include('newsong.php');
?>
</noscript>

</div>

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

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