【问题标题】:Auto update comment count inside ajax prepended div自动更新 ajax 前置 div 内的评论计数
【发布时间】:2017-01-05 00:04:49
【问题描述】:

我想要做的是自动更新由 ajax 构建的任何前置 div 的评论计数。所以基本上替换了ajaxed响应div commentprint

success: function(data) {
    $.each(data.posts, function(i, response) {
        $("#homestatusid").prepend("<div id='commentprint"+response['streamitem_id']+"'>Comments "+response['num']+"</div>")[
    }
});

我有一个名为 ajaxcommentcount.php 的页面。这是响应的来源并替换 commentprint。我只是不知道该怎么做。

【问题讨论】:

  • 抱歉,我没看到该评论数应该添加到哪里
  • 我想替换已经被ajax前置的div。 &lt;div id='commentprint"+response['streamitem_id']+"'&gt;Comments "+response['num']+"&lt;/div&gt;
  • 所以我需要有一些函数在 setInterval 中加载 ajaxcommentcount.php 页面,然后以某种方式替换新插入的 div。 &lt;div id='commentprint"+response['streamitem_id']+"'&gt;Comments "+response['num']+"&lt;/div&gt;
  • 那么这个问题对于这个网站来说太宽泛了,因为现在它是一个为我写点什么类型的问题
  • 除非您向我们展示更多代码,因为您展示的代码有些具体且可能不相关

标签: php jquery ajax get


【解决方案1】:

好的,我能够发送所需的数据并检索和更新 ajaxed div。

我加了以下就成功了

timer = setInterval(function() {
        refreshCurrentTab(streamitem_id);
    }, 5000); refreshCurrentTab(streamitem_id);

然后调用 .load() 中的函数将帖子 id 传递过来以返回并替换 div。

 function refreshCurrentTab(streamitem_id)
    {
        $('#commentprint'+streamitem_id).load('ajaxcommentcount.php?var='+streamitem_id+'');
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-07
    • 1970-01-01
    • 1970-01-01
    • 2011-01-08
    • 2019-11-21
    • 1970-01-01
    • 1970-01-01
    • 2017-09-15
    相关资源
    最近更新 更多