Created
August 12, 2018 06:24
-
-
Save epk/0a317371e6614193d28134059c72ca76 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var msgCheck = setInterval(fetch, 5e3); | |
function fetch() { | |
var n = new XMLHttpRequest; | |
n.onreadystatechange = function(e) { | |
if (4 == this.readyState && 200 == this.status) { | |
var t = JSON.parse(n.responseText); | |
console.log(t), | |
addtoDOM(t) | |
} | |
} | |
, | |
n.open("GET", "/api/posts", !0), | |
n.send() | |
} | |
function addtoDOM(e) { | |
var t = []; | |
$("#Data-table tr").each(function() { | |
t.push(this.id) | |
}); | |
for (var n = 0; n < e.length; n++) | |
t.includes(e[n]._id) || insertNewRow(e[n], e.length) | |
} | |
function insertNewRow(e, t) { | |
var n = document.getElementById("Data-table").insertRow(1); | |
n.id = e._id; | |
var s = n.insertCell(0) | |
, a = n.insertCell(1) | |
, i = n.insertCell(2); | |
s.innerHTML = e.theMessage, | |
a.innerHTML = e.username, | |
i.innerHTML = "Just now" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment