Refresh table after using jQuery .append()

Posted by Aaron Salazar on Stack Overflow See other posts from Stack Overflow or by Aaron Salazar
Published on 2010-03-29T21:05:59Z Indexed on 2010/03/29 21:13 UTC
Read the original article Hit count: 245

Filed under:
|

The following code gets a JSON object and then spits its contents out into a <table>. The first time I do it I get my JSON content just fine. However, when I refresh, the refreshed data is stuck onto the bottom of my table. How do I refresh the data to show the new data only? I tried using .remove() but there was an obvious deleting and then a refresh of data.

    $(function() {
        $('#ReportedIssue').change(function() {
            //$('.data').remove()
            $.getJSON('/CurReport/GetUpdatedTableResults', function(json) {
                for (var i = 0; i < json.GetDocumentResults.length; i++) {
                    $('#DocumentInfoTable').append(
                        "<tr class='data'>" +
                        "<td>" + json.GetDocumentResults[i].Document.DocumentId + "</td>" +
                        "<td>" + json.GetDocumentResults[i].Document.LanguageCode + "</td>" +
                        "<td>" + json.GetDocumentResults[i].ReportedIssue + "</td>" +
                        "<td>" + json.GetDocumentResults[i].PageNumber + "</td>" +
                        "</tr>"
                    );
                };
            });
        });
    });

Thank you,

Aaron

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript