我尝试在几秒钟后自动重新加载div,但它在Chrome中无法正常工作

时间:2013-08-12 11:35:25

标签: ajax html reload seconds

这是主要代码。请检查一下。是什么导致了这场冲突。

<script type="text/javascript">
$(document).ready(function () 
{
  setInterval(function() 
  {
    $.get("ajax_files/manage_friend_requests.php", function (result) 
    {
      $('#all_friends_requests').html(result); // This is the div i am reloading again and again after some seconds.
          });
        }, 9000);
    });
</script>

1 个答案:

答案 0 :(得分:0)

你应该更加安全:

$(document).ready(function(){
    setInterval(function(){
        $.ajax({
            type: "GET",
            url: "ajax_files/manage_friend_requests.php"
        }).done(function(result) {
            var $friends_requests = $('#all_friends_requests');
            if ($friends_requests.length > 0) {
                console.log('Received: '+result);
                $friends_requests.html(result);
                console.log('UPDATED friends requests');
            } else {
                console.log('CANNOT access friends requests container');
            }
        });
    }, 9000);
});

根据控制台显示的内容,您可能会将问题作为证据。