Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery Ajax淡入MySQL的新结果_Jquery_Mysql_Ajax - Fatal编程技术网

Jquery Ajax淡入MySQL的新结果

Jquery Ajax淡入MySQL的新结果,jquery,mysql,ajax,Jquery,Mysql,Ajax,我有一个类似于FaceBook的系统,其中帖子会从MySQL中的一个表中自动更新。目前,它只是每10秒刷新一次div。代码如下: <script type="text/javascript"> var auto_refresh = setInterval( function(){ $('#refresh').load('index.php?_=' +Math.random()+' #refresh').fadeIn("slow"

我有一个类似于FaceBook的系统,其中帖子会从MySQL中的一个表中自动更新。目前,它只是每10秒刷新一次div。代码如下:

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

var auto_refresh=setInterval(
函数(){
$('#refresh').load('index.php?'='+Math.random()+'#refresh').fadeIn(“慢”);
}, 10000);
我希望只有在MySQL表中有新行并且新结果淡入时才更新div。
有没有办法做到这一点?我到处都找过了,什么都试过了,但似乎什么都没用

无论您在服务器端编程中使用何种语言,google long polling都是对其进行研究的一种方式。我正在使用java和comet api

我知道怎么做了。如果有人有同样的问题,下面是我使用的:

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);

您是否结合ajax搜索推送通知?我搜索过,但找不到任何东西…如果没有IE,将会有很棒的Web Socket API,但是…:-/我试过了,但找不到。如果数据库中有新内容,我只想让div更新。