blob: 20f1a7dbd3698e63977fcdde5d1f45e04a9458c8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
const search = document.getElementById("search");
const results = document.getElementById("results");
search.addEventListener("submit", function (ev) {
const url = new URL(this.action);
url.search = new URLSearchParams(new FormData(this)).toString();
const res = fetch(url, {
headers: {
fetch: "true",
},
})
.then(function (res) {
window.history.pushState(null, null, url);
if (res.ok) {
return res.text();
} else {
throw new Error(res.statusText);
}
})
.then(function (html) {
results.innerHTML = html;
})
.catch(function (error) {
console.error("fetch failed", error);
});
ev.preventDefault();
});
|