php - 无法使用ajax更新页面

标签 php jquery ajax

我想每 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/

相关文章:

javascript - 非本地域上的 iFrame scrollTop

javascript - 我如何在 javascript 中转义 Bullet 字符,这样 tomcat 就不会死于 ajax 调用?

php - 获取多维数组中的关键级别深度?

php - 在 woocommerce 的结帐页面中显示更新的数据

php - 命令不同步;您现在无法使用 mysql 存储过程在 SugarCRM 中运行此命令

jQuery 解析 JSON 错误

php - 如何停止基于 EXIF 'orientation' 数据的 PHP iMagick 自动旋转图像

jquery - 我需要一个 jquery Accordion 来为每个部分的箭头图标使用不同的图像文件

javascript - Laravel Ajax 图片上传预览不起作用?

javascript - Angular JS ng-click HTML 由 InnerHTML 设置,未达到作用域方法