I currently have an AJAX request to update an HTML Table from a JSON file. I now want a way to alert the changes, alerting with new table items that have been added.
Below is an example of how the HTML table is being populated. I've tried storing the JSON request into JSON.stringify, storing that into a variable and then comparing that to the last time it ran.. no luck, I only return a true/false, I'd like the compare to return the difference between old and new data.
function populate_table(){
$(document).ready(function(){
$.getJSON("data.json", function(data){
var update_table = '';
$.each(data, function(key, value){
update_table += '<tr>';
update_table += '<td>'+value.name+'</td>';
update_table += '<td>'+value.date+'</td>';
update_table += '<td>'+value.address+'</td>';
update_table += '<td>'+value.phone+'</td>';
update_table += '</tr>';
});
$('#my_table tbody').html(update_table);
});
});
};
populate_table();
setInterval(function(){
populate_table()
}, 5000);
Without changing the back end JSON population, is there a way to compare the new AJAX data coming in with the data that came last time, find the differences, and alert? Any help would be greatly appreciated.