website/js/customElements/blogIndex.js

26 lines
970 B
JavaScript
Raw Normal View History

2021-04-12 19:45:30 +02:00
class BlogIndex extends HTMLElement {
constructor() {
super();
let xhr = new XMLHttpRequest();
let ul = document.createElement("ul");
xhr.onreadystatechange = () => {
if(xhr.readyState === 4 && 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>
2021-04-13 10:17:35 +02:00
<p class="center"><a href="/post.html?id=${element["id"]}"><button>Mehr lesen</button></a></p>
2021-04-12 19:45:30 +02:00
</article>
`;
});
this.appendChild(ul);
}
}
xhr.open("GET", "/API/getBlogElements.php?position=index");
xhr.send();
}
}
customElements.define("jl-blog_index", BlogIndex);