I'm trying to finish an who's online script but I am running into some issues with repeating usernames with my auto refresh function. Is there a way in jQuery to find previous values returned and if found, skip showing duplicate usernames?
Here is my code:
$(document).ready(function() {
$.ajax({
type: "GET",
url: "/members/groups/get-one-group-members-online/" + location.pathname.split("/")[4],
dataType: "json",
}).done(function(msg) {
$.each(msg.display_name, function(i, item) {
$("#members-online").append(msg.display_name[i] + "<br>");
});
}).fail(function() {
$('#members-online').html("Error retrieving online group members");
});
});
function reloadElement() {
$.ajax({
type: "GET",
url: "/members/groups/get-one-group-members-online/" + location.pathname.split("/")[4],
dataType: "json",
}).done(function(msg) {
$.each(msg.display_name, function(i, item) {
// how to not show repeating values?
$("#members-online").append(msg.display_name[i] + "<br>");
});
}).fail(function() {
$('#members-online').html("Error retrieving online group members");
});
}
setInterval(function() {
reloadElement()
}, 5000);
and the actual html element:
<p id="members-online"></p>
Any help would be appreciated. I can try and add more information if it my question is unclear.
Thanks!