class commentsDisplay extends HTMLElement { constructor() { super(); let path = window.location.pathname; let pageName = path.split("/").pop(); pageName = pageName.split(".")[0] let xhr = new XMLHttpRequest(); xhr.onreadystatechange = () => { if (xhr.readyState === 4 && xhr.status === 200){ let comments = JSON.parse(xhr.responseText); comments.forEach((element) => { this.innerHTML += `

${element["name"]}

${element["comment"]}

`; }); } } xhr.open("GET", "/API/projectComments.php?article=" + pageName); xhr.send(); } } customElements.define("jl-comments_display", commentsDisplay);