I'm creating a forum and i want the comments to appear with their dates, this is the html:
<div id="forum" class="panel panel-default">
<ul class="list-group">
</ul>
</div>
I'm appending the elements with jquery:
$.ajax({
url: '../public/comment',
type: 'GET',
dataType: 'json',
success:function(response) {
$('#forum ul').empty();
for (var i in response['comments'])
{
$('#forum ul').append('<li class="list-group-item"> <ul> <li class="list-group-item">' +
response['comments'][i].date + '</li> <li class="list-group-item">' +
response['comments'][i].comment + '</li> </ul> </li> ');
}
}
});
But for every comment that i append to the forum the rest of the comments are duplicated and attached to it. If i have three comments it shows 7, if i have 4 it shows 15.
I realize that deleting the ul tags from the jquery solves the problem, but i need these tags for aesthetic reasons. what can be wrong?