$( document ).ready( function(){
//this will fire once the page has been fully loaded
$( '#comment-post-btn' ).click( function(){
comment_post_btn_click();
});
});
function comment_post_btn_click()
{
//Text within textarea which the person has entered
var _comment = $( '#comment-post-text' ).val();
var _userId = $( '#userId' ).val();
var _userName = $('#userName').val();
if( _comment.length > 0 && _userId != null )
{
//procced with ajax callback
$('.comment-insert-container').css('border' , '1px solid #e1e1e1' );
$.ajax({
type: "POST",
url: "/ajax/comment_insert.php",
data: {
task : "comment_insert",
userId : _userId,
comment : _comment
},
error : function( )
{
console.log("Error: " );
}
,
success : function(data)
{
comment_insert( jQuery.parseJSON(data));
console.log( "ResponseText: " + data);
}
});
console.log( _comment + " UserName: " + _userName + " User Id: " + _userId );
}
else
{
//the textaarea is empty, lets put a border of red in italics
//in a second
$('.comment-insert-cotainer').css('border' , '1px solid #ff0000 ');
console.log( "The text area was empty" );
}
//remove the text from the text area, ready for another comment
//possibly
$( '#comment-post-text' ).val("");
};
function comment_insert( data )
{
var t = '';
t += '<li class="comment-holder" id="_'+data.comment_id+'">';
t += '<div class="user-img">';
t += '<img src="'+data.profile_img+'" class="user-img-pic" />';
t += '</div>';
t += '<div class="comment-body">';
t += '<h3 class="username-field">'+data.userName+'</h3>';
t += '<div class="comment-text">'+data.comment+'</div>';
t += '</div>';
t += '<div class="comment-buttons-holder">';
t += '<ul>';
t += '<li class="delete-btn">X</li>';
t += '</ul>';
t += '</div>';
t += '</li>';
$( '.comments-holder-ul' ).prepend( t );
}
Hi all, I was wondering if somoneone could help me out with my problem. I am a complete beginner, so you may have to dumb things down for me lol. But I've been trying to make a comments box for my website and following a tutorial on youtube. I'm upto about lesson 11 but i can't get past it because it doesn't work for me and the guy who posted the tutorial doesn't seem to bother replying to comments.
Can someone take a look at my code and try help where I am going wrong?
I think the problem maybe that it is a little outdated. I've already changed the ajax part from the tutorial, but it's still not working right. The console is telling me that it is a problem with : comment_insert( jQuery.parseJSON(data));
Thanks.