我想每 5 秒更新一个页面,其中包含来自另一个页面的 html 链接集,但它不起作用。如果我在浏览器上手动刷新页面,它只会更新页面。请我需要帮助
HTML 页面
<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>
最佳答案
您应该将回调函数作为 setInterval
的参数传递
喜欢:
setInterval(upd, 5000);
upd(); /*Add this so that you will call the ajax immediately after loading and no need to wait for 5seconds*/
您应该删除代码中的 ()
。
关于php - 无法使用ajax更新页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47565414/