我想每隔5秒从另一个页面更新一组带有html链接的页面,但它不起作用。如果我在浏览器上手动刷新页面,它只会更新页面。我需要帮助
HTML PAGE
<div id="sto"></div>
<script>
function upd(){
$('#sto').html('');
$.ajax({
url:base_url+'process/ajax/get3.php',
cache: false,
async: false,
dataType: 'html',
success: function(resp)
{
//$('#sto').html(resp);
$('#sto').append(resp);
}
})
}
setInterval(upd(), 5000)
</script>
PHP (get3.php - links generated from db)
<ul class="chat-history" id="group_history_2">
<li><span class="user">Test Patient</span><p>ddd</p><span class="time">04:10</span></li>
<li><span class="user">Test Patient222</span><p>ddd</p><span class="time">04:10</span></li>
<li><span class="user">Test Patient333</span><p>ddd</p><span class="time">04:10</span></li>
</ul>
答案 0 :(得分:3)
您应该将回调函数作为setInterval
喜欢:
setInterval(upd, 5000);
upd(); /*Add this so that you will call the ajax immediately after loading and no need to wait for 5seconds*/
您应该删除代码中的()
。