mcsCustomscrollbar append new content not working
Posted
by
Dariel Pratama
on Stack Overflow
See other posts from Stack Overflow
or by Dariel Pratama
Published on 2014-06-13T03:21:41Z
Indexed on
2014/06/13
3:24 UTC
Read the original article
Hit count: 113
JavaScript
|jQuery
i have this script in my website.
$(document).ready(function(){
var comment = $('textarea[name=comment_text]').val();
var vid = $('input[name=video_id]').val();
$('#add_comment').on('click', function(){
$.post('<?php echo site_url('comment/addcomments'); ?>', $('#comment-form').serialize(), function(data){
data = JSON.parse(data);
if(data.userdata){
var date = new Date(data.userdata.comment_create_time * 1000);
var picture = data.userdata.user_image.length > 0 ? 'fileupload/'+data.userdata.user_image:'images/no_pic.gif';
var newComment = '<div class="row">\
<div class="col-md-4">\
<img src="<?php echo base_url(); ?>'+picture+'" class="profile-pic margin-top-15" />\
</div>\
<div class="col-md-8 no-pade">\
<p id="comment-user" class="margin-top-15">'+data.userdata.user_firstname+' '+data.userdata.user_lastname+'</p>\
<p id="comment-time">'+date.getTime()+'</p>\
</div>\
<div class="clearfix"></div>\
<div class="col-md-12 margin-top-15" id="comment-text">'+data.userdata.comment_text +'</div>\
<div class="col-md-12">\
<div class="hr-grey margin-top-15"></div>\
</div>\
</div>';
$('#comment-scroll').append($(newComment));
$('#comment').modal('hide');
}
});
});
});
what i expect when a comment added to the DB and the PHP page give JSON response, the new comment will be added to the last line of $('#comment-scroll')
. #comment-scroll is also have custom scroll bar by mcsCustomscrollbar.
the above script also hiding the modal dialog when comment saved and it's working fine which is mean data.userdata is not empty, but why the append()
isnt?
© Stack Overflow or respective owner