I am working with php ajax where I have to append some long html so I use html function for this job and it was working for me before.But this time when i try to append item using html function its clear all the li inside ul and then append data and if i try to append the data again its does not append li again .I cant figure out what is the main problem but i use the same way before in my code but this time its clear all the li and then append. Here is my code.
//UL where i have to append data
<ul class="review-list">
</ul>
Here is my php ajax response
echo "<li>
<div class='product-comment'>
<img src='assetsimagesiconsauthor.png alt=''>
<div class='product-comment-content'>
<p class='meta'>
<strong>$review_user_name</strong> - <span>$date</span>
<div class='description'>
<p>$review_comment</p>
</div>
</div>
</div></li>";
Here is my jquery code from ajax response
success:function(response){
if(response == 2){
window.location.href = 'loginregister.php';
}else{
$('.review-list').html(response);}}
2
Answers
You can simply use jQuery append() function.
By using
append()
your existingli
Will stay and all the other data will be appended afterwardsChange your
else
To this and it will work fine.Use the append method instead of html method in your else statement