2

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='assets\images\icons\author.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 2

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)
Sign up to request clarification or add additional context in comments.

10 Comments

@Azeez Are you sure your Ajax `response’ has the data you are appending ?
@Azeez can you add your full Ajax jquery code. What dataType you are using ?
Use console.log(response) to check what exactly is being returned in response.
its working buddy thnaks but before this i use html function why thats not working
@Azeez glad to hear that. Happy coding.
|
1

Use the append method instead of html method in your else statement

$('.review-list').append(response);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.