我有一个setinterval代码更新div。当在同一系统上的两个单独的浏览器中进行测试时,此方法工作正常,但是当我在单独的Mac和PC上进行在线测试时,它停止了。

代码如下:

Javascript:

    function setupAjaxIntervalDiscuss(){
    setInterval(function()
    {
    var datastring = 'refreshchat=true&projid=' + proj_id + '&uid=' + uid;
    ajaxUpdateDiscussion(datastring);
    }, 2000);
    }

   function ajaxUpdateDiscussion(ajaxdata){
    $.ajax({
        type: "POST",
        url: "uploaddata.php",
        data: ajaxdata,
        success: function(data){
        $("#discussresult").html(data);
        refreshNav();//Updating a scrollbar styled with JS
                    }
        });
  }


PHP(此更新仅在此处提供参考):

 if(isset($_POST["refreshchat"])){
 $user_id= $_POST['uid'];
 $proj_id=$_POST['projid'];
 echo '<img class="closeddiscuss" src="images/closey.png" title="close" alt="close"/>';
  $get_discuss_query = "SELECT * FROM discuss INNER JOIN user ON discuss.user_id=user.user_id
                        WHERE discuss.project_id=$proj_id ORDER BY discuss_id DESC";
                        $get_discuss_result=mysql_query($get_discuss_query);
                        while($row=mysql_fetch_assoc($get_discuss_result)){
                        $text = nl2br($row['discuss_text']);
                        $name = $row['user_name'];
                        $user_profileimageurl = $row['user_profileimageurl'];
                        echo '<div class="discussbubble"><p>'.$text.'</p><img class="smallprofileimage" src="'.$user_profileimageurl.'" alt="user profile image"/> by '.$name.'</div>';
                        }
   }

最佳答案

我了解页面没有更新。也许它被缓存了?尝试:

function ajaxUpdateDiscussion(ajaxdata){
    $.ajax({
        type: "POST",
        url: "uploaddata.php?t=" + Math.random(),
        data: ajaxdata,
        success: function(data){
        $("#discussresult").html(data);
        refreshNav();//Updating a scrollbar styled with JS
        }
    });


}

07-24 09:17