34 lines
No EOL
1.3 KiB
JavaScript
34 lines
No EOL
1.3 KiB
JavaScript
class BlogIndex extends HTMLElement {
|
|
constructor() {
|
|
super();
|
|
let xhr = new XMLHttpRequest();
|
|
let ul = document.createElement("ul");
|
|
xhr.onreadystatechange = () => {
|
|
if (xhr.readyState === 4) {
|
|
if (xhr.status === 200) {
|
|
let blog = JSON.parse(xhr.responseText);
|
|
blog.forEach((element) => {
|
|
this.innerHTML += `
|
|
<article class="breakWord">
|
|
<h2>${element["title"]}</h2>
|
|
<p breakWord>${element["content"]}</p>
|
|
<p class="center"><a href="/post.html?id=${element["id"]}"><button>Mehr lesen</button></a></p>
|
|
</article>
|
|
`;
|
|
});
|
|
this.appendChild(ul);
|
|
|
|
} else {
|
|
let p = document.createElement("p");
|
|
p.innerText = "Leider konnte dieser Inhalt nicht geladen werden, bitte versuche die Seite neu zu laden oder komme später wieder zurück";
|
|
this.appendChild(p);
|
|
|
|
}
|
|
}
|
|
}
|
|
xhr.open("GET", "/API/getBlogElements.php?position=index");
|
|
xhr.send();
|
|
}
|
|
}
|
|
|
|
customElements.define("jl-blog_index", BlogIndex); |