JSON字符串覆盖?

时间:2014-08-27 00:15:50

标签: php ajax json

我正在创建一个视图更多的评论脚本,我显示了一定数量的评论..目前2但是像Facebook一样,如果有更多它说视图所有..在我的测试帖子上我有四个总共有评论,2显示和2隐藏(在数据库中)。我点击此链接并拨打所有评论,然后将替换现有的2并同时添加显示其他两个。

所以我几乎把所有东西放在一起。但是我被告知我需要设置一些描述的密钥,以便字符串不会相互覆盖,我无法使用成功的响应' 那我该怎么做呢?

通过JSON数组返回数据字符串

{"comment_id":"1687","comment_poster":"33","comment_streamitem":"223","comment_datetime":"2014-08-23 17:24:10","comment_content":"ggg","username":"luce","id":"33","first":"lucy","middle":"","last":"ward"}{"comment_id":"1688","comment_poster":"33","comment_streamitem":"223","comment_datetime":"2014-08-23 17:24:13","comment_content":"hh","username":"luce","id":"33","first":"lucy","middle":"","last":"ward"}{"comment_id":"1689","comment_poster":"33","comment_streamitem":"223","comment_datetime":"2014-08-23 17:24:15","comment_content":"kkk","username":"luce","id":"33","first":"lucy","middle":"","last":"ward"}{"comment_id":"1690","comment_poster":"33","comment_streamitem":"223","comment_datetime":"2014-08-23 17:24:17","comment_content":"kk","username":"luce","id":"33","first":"lucy","middle":"","last":"ward"}

ajax调用自己

<script type="text/javascript">
$(function() {
    $(".view_comments").click(function() {
        var ID = $(this).attr("id");

        $.ajax({
            type: "GET",
            url: 'viewmorecommentslink.php?comment_streamitem='+ ID,

            success: function(response){
                $("#comment_list_"+ID).append('<div class="stream_comment" id="comment_'+response['comment_id']+'" style="margin-top:0px;">\
                <table width=100%><tr><td valign=top width=30px><img class="stream_profileimage" style="border:none;padding:0px;display:inline;" border=\"0\" src=\"userimages/cropped'+response['comment_poster']+'.jpg\" onerror=this.src=\"userimages/no_profile_img.jpeg\" width=\"40\" height=\"40\" ></a><td valign=top align=left>\
                <a href="/profile.php?username='+response['username']+'">'+response['first']+' '+ response['middle']+' '+response['last']+'</a> - <abbr class="timeago" title='+response['comment_datetime']+'>'+response['comment_datetime']+'</abbr>\<div class="commentholder">'+response['comment_content']+'</div><br/>\<div id="commentactivitycontainer">\
                <a style="cursor:pointer;" onClick=\"deletecomment('+response['comment_id']+',comment_'+response['comment_id']+');\">Delete</a><a id="likecontext_'+response['comment_id']+'" style="cursor:pointer;" onClick=\"likestatuscomment('+response['comment_id']+',this.id);\">\
                <div style="width:80px; position:relative; float:left; left:40px" id="likescommentprint'+response['comment_id']+'">Like</div></a><div style="width:80px; position:relative; float:left; left:40px" id="likescommentprint'+response['comment_id']+'"></div>\
                </form><a id="dislikecontext_'+response['comment_id']+'" style="cursor:pointer;" onClick=\"dislikestatuscomment('+response['comment_id']+',this.id);\"><div style="width:90px; position:relative;top:-0px; float:left; left:200px" id="dislikescommentprint'+response['comment_id']+'">Dislike</div>\
                </a><div style="width:90px; position:relative; top:-0px; float:left; left:200px" id="dislikescommentprint'+response['comment_id']+'"></div></form></div></table></div></div>');

                $("#view"+ID).remove();
                $("#comment_list_"+ID).remove();
            }   
        });
        return false
    });
});
</script>

0 个答案:

没有答案