chore: fixes
This commit is contained in:
parent
6d9e3ca152
commit
cd9f2014a8
1 changed files with 26 additions and 27 deletions
|
|
@ -16,35 +16,34 @@
|
|||
</main>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- JS LOADER -->
|
||||
<script>
|
||||
function loadAbout() {
|
||||
var target = document.getElementById("content");
|
||||
window.addEventListener("load", () => {
|
||||
const target = document.getElementById("content");
|
||||
console.log("target:", target);
|
||||
|
||||
if (!target) return;
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
fetch("/about.html")
|
||||
.then(res => {
|
||||
console.log("status:", res.status);
|
||||
return res.text();
|
||||
})
|
||||
.then(html => {
|
||||
const temp = document.createElement("div");
|
||||
temp.innerHTML = html;
|
||||
|
||||
xhr.open("GET", "/about.html", true); // IMPORTANT: same-origin
|
||||
const section = temp.querySelector("#aboutSection");
|
||||
|
||||
xhr.onload = function () {
|
||||
if (xhr.status === 200) {
|
||||
target.innerHTML = extractAboutHTML(xhr.responseText);
|
||||
} else {
|
||||
target.innerHTML =
|
||||
"<center><h2>About</h2></center>" +
|
||||
"<center><p>Could not load about.html (HTTP error)</p></center>";
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = function () {
|
||||
target.innerHTML =
|
||||
"<center><h2>About</h2></center>" +
|
||||
"<center><p>Network error loading page</p></center>";
|
||||
};
|
||||
|
||||
xhr.send();
|
||||
}
|
||||
target.innerHTML = section
|
||||
? section.innerHTML
|
||||
: "<h2>About</h2><p>Failed to load content</p>";
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
target.innerHTML = "<h2>About</h2><p>Error loading page</p>";
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue