I have a script that returns data into a table, this works to a degree. The issue I am having is the script keep going round in some sort of loop and adding the same data to more rows in the table.
function refreshDataLiveEvents() {
$.ajax({
type: 'POST',
url: 'check_current_events.php',
data: $('#departcount').serialize(),
dataType: "json", //to parse string into JSON object,
success: function (data) {
if (data) {
var len = data.length;
var txt = "";
if (len > 0) {
for (var i = 0; i < len; i++) {
if (data[i].Department && data[i].Depart) {
txt += "<tr><td>" + data[i].Department + "</td><td>" + data[i].Depart + " </td></tr>";
}
}
if (txt != "") {
$("#table").append(txt);
}
}
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert('error: ' + textStatus + ': ' + errorThrown);
}
});
return false;
}
setInterval(refreshDataLiveEvents, 3000);
Can anyone see where or what I am doing wrong. Any help would be great. Many thanks in advance.