Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9086693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:33:04+00:00 2026-06-16T21:33:04+00:00

I have a section on a webpage that is generated like this. <table> <c:forEach

  • 0

I have a section on a webpage that is generated like this.

<table>
    <c:forEach items="${personList}" var="person">
        <tr>
            <td>
            </td>
            <td>
                <h2 style="text-align:left;">${person.reviewName}</h2>              
                <h2 style="text-align:right;">by ${person.name}</h2>
            </td>
        </tr>
        <tr>
            <td style="text-align:right;">
                <img src="<c:url value="/resources/${person.id}.jpg" />" >
            </td>
            <td>
                ${person.review}
            </td>
        </tr>
        <tr>
            <td>
            </td>
            <td>
                <div id="${person.id}" class="comment">comments</div>
            </td>
        </tr>
        <tr id="ins${person.id}">
            <td>

            </td>
            <td id="comments${person.id}" style="display:none">
            <div id="ins${person.id}">
                <table>
                        <c:forEach items="${person.comments}" var="comment">
                            <tr>
                                <td>
                                    ${comment} 
                                </td>
                            </tr>
                        </c:forEach>
                </table>
                Add Comment:
                <textarea id="comment${person.id}"></textarea>
                <button onClick="addComment(${person.id})">add Comment</button>
            </div>
            </td>
        </tr>
    </c:forEach>
</table>

I’m trying to use JQuery.load() to instantly update the comments section when a new comment is added like this.

function addComment(id) {
    $.getJSON("addComment", {id:id, comment:$("#comment" + id).val()});
    $("#comments2").load("home #ins2");
}

The problem is when the when I click to add the comment it only displays the comment I previously added, meaning the comments section is always one comment behind. If I load the page directly after adding the comment it displays as it should. Another strange thing is that when I do add the comment a blank line is inserted a the top of the comments, which isn’t there/goes away when I load the page directly.

I thought this might be some kind of cache problem so tried to turn it off using

$.ajaxSetup ({
    cache: false
});

However this made no difference.

I’m really at a dead end with this. Is it something to do with the section I’m pulling with load() being a forEach tag?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T21:33:05+00:00Added an answer on June 16, 2026 at 9:33 pm

    You need to load your comments in the success callback of the getJSON method to wait the end of the getJSON call before reload your div.

    function addComment(id) {
        $.getJSON("addComment", {id:id, comment:$("#comment" + id).val()}, function(){
            $("#comments2").load("home #ins2");
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a section of a webpage that loads a JavaScript file from an
I have a comments section on a webpage that I have hidden initially and
I have a current webpage that is broken into two sections. The top section
I have a section on my website that when a user clicks I would
I have a section of a website that has three divs next to each
I have a section of code that can be summarised as follows; void MyFunc()
I have a section of my application that allows for people to send an
On my page I have a section where I would like to pull in
I'm after creating a webpage that includes a blog section and it currently displays
I currently have an iframe that's setup to cover most of my webpage with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.