I have a records which I have populated in HTML table format. I have an achor tag with trash-can image at the last column. Upon clicking on the Image I am trying to delete the row and populate the table again with the fresh data. I am using $.getJSON() call and iterating a list to form the rows of the table. The action is getting called and the respective record is getting deleted from the database table but the table in the jsp page is not getting refreshed. Please look at the below two Images to better understand my problem.
I have clicked on the 1st row trash-can to remove the 1st row of the table but the table is not getting refreshed, it is appending the whole records to the end of the table. If I refresh the page then it table is showing up correctly. below is my JQuery code. Some one please suggest me in resolving this issue.
JQuery Script:
$(".deleteUserIncomesJson").click(function(e){
e.preventDefault();
var tempID = $(this).attr('data'); //Fetch income id
$.getJSON("deleteUserIncomesJson",{incomeID:tempID},function(data){
$(this).closest('tr').remove();
$.each(data.incomesList,function(index){
$(".defaultTable").append("<tr><td>"+data.incomesList[index].catergory.userCodeName+"</td>"+
"<td>"+data.incomesList[index].payee.payeeName+"</td>"+
"<td>"+data.incomesList[index].description+"</td>"+
"<td>"+data.incomesList[index].transactionDate+"</td>"+
"<td>"+data.incomesList[index].amount+"</td>"+
"<td> </td>"+
+"</tr>");
});
});
});
HTML Code:
<a style="text-decoration: none" class="deleteUserIncomesJson" href="#" id="{<tags:property value="incomeID"/>}" data="<tags:property value="incomeID"/>">
<img width="20px" height="20px" src="<tags:url value="/image/Trash.png"/>" height="15"/>
</a>