Hi friends.My friends are asked to me how to create facebook style comment .Thats why i have wrote this article.I have used PHP and Javascript to add comment.Let's have a look.
In this you will learn the following things:
1.SESSION
2.Ajax Method(GET)
Functionality Files:
1. index.php
Please share your comments and feedback.Thanks
In this you will learn the following things:
1.SESSION
2.Ajax Method(GET)
Functionality Files:
1. index.php
HTML Code
<div class="container">
<div class="content">
<div id="commentscontainer">
<div class="comments clearfix">
<div class="pull-left lh-fix"> <img src="img/default.gif"> </div>
<div class="comment-text pull-left"> <span class="color strong"><a href="#">Vinoth</a></span> Hello Friends <span class="info"><abbr class="time" title="2014-04-024T21:50:03+02:00"></abbr></span> </div>
</div>
<div class="comments clearfix">
<div class="pull-left lh-fix"> <img src="img/default.gif"> </div>
<div class="comment-text pull-left"> <span class="color strong"><a href="#">Code Innovators</a></span> What's up?? <span class="info"><abbr class="time" title="2014-04-024T21:50:03+02:00"></abbr></span> </div>
</div>
</div>
<div class="comments clearfix">
<div class="pull-left lh-fix"> <img src="img/default.gif"> </div>
<div class="comment-text pull-left">
<textarea class="text-holder" placeholder="Write a comment.." id="message"></textarea>
</div>
</div>
</div>
</div>
jQuery Code
<script type="text/javascript">
$(document).ready(function() {
var msg = '#message';
$('.time').timeago();
$(msg).autosize();
$('#post_comment').click(function() {
$(msg).focus();
});
$(msg).keypress(function(e) {
if(e.which == 13) {
var val = $(msg).val();
$.ajax({
url: 'php/ajax.php',
type: 'GET',
data: 'token=<?php echo $token; ?>&msg='+escape(val),
success: function(data) {
$(msg).val('');
$(msg).css('height','14px');
$('#commentscontainer').append(data);
$('.time').timeago();
}
});
}
});
$('#like_post').click(function() {
var count = parseFloat($('#count').html()) + 1;
if(count > 1) {
$('#if_like').html('You and');
$('#people').html('others');
} else {
$('#if_like').html('You like this.');
$('#likecontent').hide();
}
$('#like_post').hide();
$('#unlike_post').show();
});
$('#unlike_post').click(function() {
var count = parseFloat($('#count').html()) - 1;
if(count < 1) {
$('#likecontent').show();
}
$('#unlike_post').hide();
$('#like_post').show();
$('#if_like').html('');
$('#people').html('people');
});
});
</script>
nice ...:)
ReplyDeletethis is cooooool (y)
ReplyDelete