skip to Main Content

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


  1. You can simply use jQuery append() function.

    By using append() your existing li Will stay and all the other data will be appended afterwards

    Change your else To this and it will work fine.

    $('.review-list').append(response)
    
    Login or Signup to reply.
  2. Use the append method instead of html method in your else statement

    $('.review-list').append(response);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search