day13--评论功能

类似“畅言”、“多说”的评论功能
css

.commonbox{ 
  border:1px solid #ccc; 
  padding: 1px;
  margin:1px;
}

数据库存储结构

{ 
  "_id":ObiectId("57baf5b16bd4cda73990cfd0"), 
  "_gid":"5703a45ed3db3a121c4a3d2e", "_status":0,
  "_contents":[
    { 
      "_userPhone":"12345678911", 
      "_content":"test", 
      "_id":ObjectId("57baf5b16bd4cda73990cfd1"), 
      "_addTime":ISODate("2016-08-22T12:53:05.032Z") 
    },
    { "_userPhone":"12345678911", 
      "_content":"test",     
      "_id":ObjectId("57baf5b16bd4cda73990cfd1"), 
      "_addTime":ISODate("2016-08-22T12:53:05.032Z") 
    },
    { 
      "_userPhone":"12345678911",
      "_content":"test", 
      "_id":ObjectId("57baf5b16bd4cda73990cfd1"), 
      "_addTime":ISODate("2016-08-22T12:53:05.032Z") 
    }
  ],
  "__v":3
}

ajax回复功能

$('.goodscsheia').click(function(){
    var content = $('#sendM').val();
    var cid = $(this).data('cidd');
    $.ajax({
        url:'http://x.x.x.x:3000/admin/disAdd',
        data:{
            id:cid,
            con:content
        },
        type:'post',
        dataType:'json',
        success:function(data){
            if(data.result == 'yes'){
                $('#sendM').val(' ');
                getDiscuss();
            }else if(data.result == 'noLogin'){
                $('#hiddenLogin').click();
            }
        }        
    });
});

ajax评论

function doDiscuss(){
    var con = $('#sendM').val();
    $.ajax({
        url:'http://x.x.x.x:3000/admin/doDiscuss',
        data:{
            content:con,
            gid:goodsId
        },
        dataType:'json',
        type:'post',
        success:function (data){
            if(data.result == 'yes'){
                $('#sendM').val(' ');
                getDiscuss();
                alert('发布成功');
            }else if(data.result == 'noLogin'){
                $('#hiddenLogin').click();
            }
        }
    });
}

你可能感兴趣的:(day13--评论功能)