diff options
author | Alan Pearce | 2024-05-04 12:54:31 +0200 |
---|---|---|
committer | Alan Pearce | 2024-05-04 14:51:00 +0200 |
commit | 5b9e67fd5129dec75169a1a070c70f910dff6da2 (patch) | |
tree | 73a4656b60387556462e7d5384cac0919bc1da66 /frontend/static | |
parent | a2c97c10ee0a01277c51f85b15bdf8ee821f96db (diff) | |
download | searchix-5b9e67fd5129dec75169a1a070c70f910dff6da2.tar.lz searchix-5b9e67fd5129dec75169a1a070c70f910dff6da2.tar.zst searchix-5b9e67fd5129dec75169a1a070c70f910dff6da2.zip |
feat: frontend search implementation
Diffstat (limited to 'frontend/static')
-rw-r--r-- | frontend/static/search.js | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/frontend/static/search.js b/frontend/static/search.js new file mode 100644 index 0000000..20f1a7d --- /dev/null +++ b/frontend/static/search.js @@ -0,0 +1,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(); +}); |