麻烦动态刷新div [英] Trouble with dynamic refreshing div

查看:120
本文介绍了麻烦动态刷新div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在更新文件时使div更新。但它不断刷新(每秒淡出和淡入)。























c $ c>< script src =http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js>
< / script>
< ;脚本>
$(document).ready(function(){
$('#loaddiv')。load('check.chat.php');
});


var auto_refresh = setInterval(function(){
$ .ajax(
{
type:'POST',
data:id ($(#loaddiv)。html())
$:
url:check.chat.php,
成功:函数(结果) !=结果)
{
$(#loaddiv)。fadeOut(fast)
$(#loaddiv)。html(result);
$( #loaddiv)。fadeIn(slow);
}
}
});
},1000);
< / script>

< div id =loaddiv> ;< / div>

网站上的文件: *



谁知道问题所在? 这个部分:

  $(#loaddiv)。fadeOut(fast)
$( 。#loaddiv)HTML(结果);
$(#loaddiv)。fadeIn(slow);

应该是:

 ($$ load); 
$ ).fadeIn(slow);
});

在这种情况下,两个淡出同时被调用,创建一个动画队列,导致它大约在同一时间间隔再次触发。






更新



要查看日志,请执行以下操作: console.log(html:,$(#loaddiv)。html(),result:,result);


I make div which refresh when file is updated. But it continuously refresh (fade out and fade in every second).
I't source test2.php

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js>
    </script>                          
    <script> 
    $(document).ready(function() {
       $('#loaddiv').load('check.chat.php');
     });


    var auto_refresh = setInterval( function() {
    $.ajax(
        {
        type: 'POST',
        data:"id=100",
        url: "check.chat.php",
        success: function(result) 
        {
            if($("#loaddiv").html() != result)
            {
                $("#loaddiv").fadeOut("fast")
                $("#loaddiv").html(result);
                $("#loaddiv").fadeIn("slow");
           }
        }
    });
    }, 1000);
    </script>

    <div id="loaddiv"></div>

And file on site: **

Who knows what's the problem?

解决方案

This part:

$("#loaddiv").fadeOut("fast")
$("#loaddiv").html(result);
$("#loaddiv").fadeIn("slow");

Should be:

$("#loaddiv").fadeOut("fast", function(){
        $("#loaddiv").html(result);
        $("#loaddiv").fadeIn("slow");
});

In your case, both fades are called at the same time, making an animation queue, causing it to go from one phase to another in about the same time the interval triggers again.


UPDATE

To see logs, do this: console.log("html: ", $("#loaddiv").html(), "result: ", result);

这篇关于麻烦动态刷新div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆