Let's create a function and call our page with the JSON data we just assembled. That was a method I used.
https://www.w3schools.com/js/js_json_html.asp
has other ways to call the file and present it in a Div. After the function is configured I will make it update every 1 second using this method.
https://www.w3schools.com/jsref/met_win_setinterval.asp
at the end so it should stick the structure.
Code: Select all
<script>
setInterval(chat, 1000);
function chat() {
const dbParam = JSON.stringify({table:"customers",limit:4});
const xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function() {
const myObj = JSON.parse(this.responseText);
let text = "<ol class='chat'>"
for (let x in myObj) {
text += " <li class="+ myObj[x].quem +"><div class='msg'>" + "<font color='black'>" + myObj[x].name + " : " + " </font>" + "<p>" + myObj[x].content + "</p>" + "</br>" + "<time>" + myObj[x].time + "</time>" + "</div><hr/></li>";
}
text += "</ol>"
document.getElementById("chat").innerHTML = text;
}
xmlhttp.open("GET", "/message page in Json.html");
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send("x=" + dbParam);
}
</script>
</script>
Use this div to call the chat
Code: Select all
<p id="chat"></p>
-----------------------NOTE-----------------
Remember when you are creating the page with json information, you must create an array list with multiple objects. See the example of my https://hlsking.wapka.site/msg.