0

MySQL のテーブルから投稿が自動的に更新される FaceBook に似たシステムがあります。現時点では、10 秒ごとに div を更新するだけです。コードは次のとおりです。

<script type="text/javascript">
        var auto_refresh = setInterval(
        function(){
            $('#refresh').load('index.php?_=' +Math.random()+' #refresh').fadeIn("slow");
        }, 10000);
</script>

MySQL テーブルに新しい行がある場合にのみ div を更新し、新しい結果をフェードインしたいと思います。これを行う方法はありますか? どこでも検索し、すべてを試しましたが、何も機能していないようです。

4

2 に答える 2

1

Google ロング ポーリングは、サーバーサイド プログラミングに使用している言語に関係なく、それについて調査する方法です。私はJavaとコメットAPIを使用しています。

于 2013-04-15T10:53:57.973 に答える
0

やり方がわかった。誰かが同じ問題を抱えている場合、ここに私が使用したものがあります:

var cacheData;
var data = $('#refresh').html();
var auto_refresh = setInterval(
function ()
{
    $.ajax({
        url: 'index.php',
        type: 'POST',
        data: data,
        dataType: 'html',
        success: function(data) {
            if (data !== cacheData){
                //data has changed (or it's the first call), save new cache data and update div
                cacheData = data;
                //$('#refresh').fadeOut("slow").html(data).fadeIn("slow");
                //$('#refresh').fadeOut("slow").load('index.php?_=' +Math.random()+' #refresh').slideDown("slow");
                $('#refresh').fadeOut("fast");
                $('#refresh').load('index.php?_=' +Math.random()+' #refresh');
                $('#refresh').fadeIn("slow");
            }           
        }
    })
}, 1000);
于 2013-04-16T08:41:00.157 に答える