现在,我有这样一要需求。就是防新浪微博评论的数据实现。ajax实现
点击评论,传送一个ID过去,得到所有回复数据.然后显示在下面。这个要怎么实现呢?
而且还我还要跟他一样,点评论后马上显示?
通过AJAX实现。

解决方案 »

  1.   

    你都知道传ID过去用ajax实现了,还不会写嘛
      

  2.   

    传递过去后 ajax 返回json js 读取js 将数据呈现到浏览器
      

  3.   

    $("#RESUME_WORK_save").bind("click",function(){//例如触发条件是RESUME_WORK_save的点击 也可以根据滚动条高度发送ajax请求调用数据等
    var work_data="data=jsondate&.....";//post数据提交
    $.ajax({
    type:"POST",
    url:"xxx.php",//需要提交页面 
    data:work_data,
    beforeSend:function(){
    $(this).attr("disabled",true).val("请求中");
    },
    success:function(data){
    var jsonresult=JSON.parse(data);//这里可以对拿回的数据进行组装成div,将该div插入或者任意其他处理方式将他放到div容器中。例如id worklist的容器 可以看看jquery帮助文档各种插入方式都有。
    var divbox="<div>xxx</div>";
    /*
    内部插入
    append(content | fn)  
    appendTo(content) 
    prepend(content | fn) 
    prependTo(content) 
    外部插入
    after(content | fn) 
    before(content | fn) 
    insertAfter(content) 
    insertBefore(content) 
    */
    $("#worklist").after(divbox);//worklist之后插入divbox 可以实现动态载入。
    }
    });
    });
      

  4.   

    LZ的就是基本代码的实现了
    还有LZ在显示评论列表的时候可以有两个方式
    一个就是在请求服务器端的时候,在服务器端将评论列表的html直接拼接好输出
    另一个就是在服务器端仅仅返回相关评论的json数据,在客户端获取或解析json拼接html再追到加你所需要的html里面
      

  5.   

    function T_c_p_replybtns(obj)
    {
    var weiboid = $(obj).attr('weiboid');
    $.ajax({
    url:'<?php echo site_url('home/getWeiboComment')?>',
    type:'GET',
    dataType:'json',
    data:{"weiboid":weiboid},
    beforeSend:function(){
                     $(this).attr("disabled",true).val("请求中");
                 },
    success:function(json)
    {
     var reply_a = $(obj).parents(".trend_content_pic");
     var reply_b = $(obj).parents(".trend_box").find(".trend_content_pic").not(reply_a)
     //var reply_mod = $('<div class="t_c_p_replybox clearfix"> <span class="t_c_p_replyboxicon"></span><form action="" method="get"> <div class="p_i_reply p_i_reply_w2 clearfix"><div class="p_i_textarea_box"><textarea cols="" rows="" class="p_i_textarea p_i_textarea_w2">'+json.data.commentid+'</textarea></div><div class="p_i_reply_btnbox clearfix"><a href="#" class="p_i_reply_btn"></a><a href="javascript:void(0);" class="face_box face_box_m" onclick="face_trigger(this);return false;"></a></div><div class="p_i_reply_list clearfix"><div class="reply_list_mod r_l_m_563"> <div class="r_l_m_avatar"></div><div class="r_l_m_contentb"><div class="r_l_m_content"> <a href="#" class="r_c_name">最温馨家居</a>:的好,相信有这么好送货师傅, 贵店的生意也一定会更好!<p class="r_l_m_tool"> <span class="r_c_date">[ 2012-07-21]</span><a href="javascript:void(0);" class="r_c_btn" infoid="123" onclick="ClickReply(this);return false;"></a></p></div></div></div> <div class="reply_list_mod r_l_m_563"><div class="r_l_m_avatar"></div><div class="r_l_m_contentb"><div class="r_l_m_content"> <a href="#" class="r_c_name">最温馨家居</a>:沙发质量还可以,但是我全5分要送给送货的师傅,真是超级好!昨天我家只有位70岁的奶奶和4岁的女儿,加上我3个人,师傅本是送到楼下不负责送上楼的,看我家男人不在家就主动帮忙和我一起把沙发抬到了楼上,而且还等我们拆开检查后签字离开,真是非常的好,相信有这么好送货师傅, 贵店的生意也一定会更好!<p class="r_l_m_tool cearfix"> <span class="r_c_date">[ 2012-07-21]</span> <a href="javascript:void(0);" class="r_c_btn" infoid="123" onclick="ClickReply(this);return false;"></a></p></div></div></div> </div></div></form></div>')
      

  6.   

    像这样的{"data":[{"commentid":"231","weiboid":"292","uid":"10000","content":"KSLDFJSKL;FKJSL","datetime":"1350355517","syncid":"0","synctype":"0","replayuid":"0","replaycid":"0"}],"total_rows":1}怎么去篇历他
      

  7.   

    这个功能已经完成过一次了,其实就是PHP返回JSON,然后用jquery插入HTML代码append appendTo,但是加载的时候要做好控制,注意不要造成客户端重复加载。
      

  8.   

    问题是,像这样的
    {"data":[{"commentid":"1","weiboid":"47","uid":"100001","content":"34535","datetime":"1350355452","syncid":"0","synctype":"0","replayuid":"0","replaycid":"0"},{"commentid":"2","weiboid":"47","uid":"100000","content":"34535","datetime":"1350355456","syncid":"0","synctype":"0","replayuid":"0","replaycid":"0"},{"commentid":"3","weiboid":"47","uid":"10016","content":"34535","datetime":"1350355471","syncid":"0","synctype":"0","replayuid":"0","replaycid":"0"},{"commentid":"37","weiboid":"47","uid":"100000","content":"656321","datetime":"1350355517","syncid":"0","synctype":"0","replayuid":"0","replaycid":"0"}],"total_rows":4}数据,我要如何篇历呢?
      

  9.   

    你这个要先转换成JSON,代码:var dt = '{"data":[{"commentid":"1","weiboid":"47","uid":"100001","content":"34535","datetime":"1350355452","syncid":"0","synctype":"0","replayuid":"0","replaycid":"0"},{"commentid":"2","weiboid":"47","uid":"100000","content":"34535","datetime":"1350355456","syncid":"0","synctype":"0","replayuid":"0","replaycid":"0"},{"commentid":"3","weiboid":"47","uid":"10016","content":"34535","datetime":"1350355471","syncid":"0","synctype":"0","replayuid":"0","replaycid":"0"},{"commentid":"37","weiboid":"47","uid":"100000","content":"656321","datetime":"1350355517","syncid":"0","synctype":"0","replayuid":"0","replaycid":"0"}],"total_rows":4}';
    var json = eval('(' + dt + ')'); 
    $(json.data).each(function(i, item){
    alert(item.commentid)
    })
      

  10.   

    jq有操作json的方法,你研究下吧,这个很基础
      

  11.   

    {
        "0": {
            "avatar": "/uploads/avatar/20121123/1353662511_41246700_small.JPG",
            "uid": "牛时髦",
            "weiboid": "295",
            "commentid": "247",
            "content": "322",
            "datetime": "2012-11-24 10:52:46",
            "syncid": "0",
            "synctype": "0",
            "replayuid": "0",
            "replaycid": "0",
            "wid": "100000"
        },
        "1": {
            "avatar": "/uploads/avatar/20121123/1353662511_41246700_small.JPG",
            "uid": "牛时髦",
            "weiboid": "295",
            "commentid": "244",
            "content": "323233",
            "datetime": "2012-11-24 10:22:35",
            "syncid": "0",
            "synctype": "0",
            "replayuid": "0",
            "replaycid": "0",
            "wid": "100000"
        },
        "smileys": [
            "<a href=\"javascript:void(0);\" onclick=\"insert_smiley('[鄙视]', 'weibocontent')\"><img src=\"http://localhost/qsjia/public/default/images/smileys/face101.png\" width=\"19\" height=\"19\" alt=\"鄙视\" style=\"border:0;\" /></a>",
            "<a href=\"javascript:void(0);\" onclick=\"insert_smiley('[登场]', 'weibocontent')\"><img src=\"http://localhost/qsjia/public/default/images/smileys/face102.png\" width=\"19\" height=\"19\" alt=\"登场\" style=\"border:0;\" /></a>",
            "<a href=\"javascript:void(0);\" onclick=\"insert_smiley('[飞吻]', 'weibocontent')\"><img src=\"http://localhost/qsjia/public/default/images/smileys/face103.png\" width=\"19\" height=\"19\" alt=\"飞吻\" style=\"border:0;\" /></a>",
            "<a href=\"javascript:void(0);\" onclick=\"insert_smiley('[尴尬]', 'weibocontent')\"><img src=\"http://localhost/qsjia/public/default/images/smileys/face104.png\" width=\"19\" height=\"19\" alt=\"尴尬\" style=\"border:0;\" /></a>",
            "<a href=\"javascript:void(0);\" onclick=\"insert_smiley('[挂了]', 'weibocontent')\"><img src=\"http://localhost/qsjia/public/default/images/smileys/face105.png\" width=\"19\" height=\"19\" alt=\"挂了\" style=\"border:0;\" /></a>",
            "<a href=\"javascript:void(0);\" onclick=\"insert_smiley('[鬼脸]', 'weibocontent')\"><img src=\"http://localhost/qsjia/public/default/images/smileys/face106.png\" width=\"19\" height=\"19\" alt=\"鬼脸\" style=\"border:0;\" /></a>",
            "<a href=\"javascript:void(0);\" onclick=\"insert_smiley('[憨笑]', 'weibocontent')\"><img src=\"http://localhost/qsjia/public/default/images/smileys/face107.png\" width=\"19\" height=\"19\" alt=\"憨笑\" style=\"border:0;\" /></a>",
            "<a href=\"javascript:void(0);\" onclick=\"insert_smiley('[好色]', 'weibocontent')\"><img src=\"http://localhost/qsjia/public/default/images/smileys/face108.png\" width=\"19\" height=\"19\" alt=\"好色\" style=\"border:0;\" /></a>",
            "<a href=\"javascript:void(0);\" onclick=\"insert_smiley('[拉脸]', 'weibocontent')\"><img src=\"http://localhost/qsjia/public/default/images/smileys/face109.png\" width=\"19\" height=\"19\" alt=\"拉脸\" style=\"border:0;\" /></a>",
            "<a href=\"javascript:void(0);\" onclick=\"insert_smiley('[流氓]', 'weibocontent')\"><img src=\"http://localhost/qsjia/public/default/images/smileys/face110.png\" width=\"19\" height=\"19\" alt=\"流氓\" style=\"border:0;\" /></a>",
            "<a href=\"javascript:void(0);\" onclick=\"insert_smiley('[求包养]', 'weibocontent')\"><img src=\"http://localhost/qsjia/public/default/images/smileys/face111.png\" width=\"19\" height=\"19\" alt=\"求包养\" style=\"border:0;\" /></a>",
            "<a href=\"javascript:void(0);\" onclick=\"insert_smiley('[伤心]', 'weibocontent')\"><img src=\"http://localhost/qsjia/public/default/images/smileys/face112.png\" width=\"19\" height=\"19\" alt=\"伤心\" style=\"border:0;\" /></a>",
            "<a href=\"javascript:void(0);\" onclick=\"insert_smiley('[思考]', 'weibocontent')\"><img src=\"http://localhost/qsjia/public/default/images/smileys/face113.png\" width=\"19\" height=\"19\" alt=\"思考\" style=\"border:0;\" /></a>",
            "<a href=\"javascript:void(0);\" onclick=\"insert_smiley('[无语]', 'weibocontent')\"><img src=\"http://localhost/qsjia/public/default/images/smileys/face114.png\" width=\"19\" height=\"19\" alt=\"无语\" style=\"border:0;\" /></a>",
            "<a href=\"javascript:void(0);\" onclick=\"insert_smiley('[抓狂]', 'weibocontent')\"><img src=\"http://localhost/qsjia/public/default/images/smileys/face115.png\" width=\"19\" height=\"19\" alt=\"抓狂\" style=\"border:0;\" /></a>"
        ]
    }像这样的格式,怎么迭代呢?