diff options
author | Ole Mathias Aa. Heggem <olemathias.aa.heggem@gmail.com> | 2025-04-13 07:18:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-13 07:18:45 +0200 |
commit | 4ea3a099b05fa910498bfbf1b2d7387118355472 (patch) | |
tree | c248cf6764412471ee3e0d1218761bee19fb396a /web/js/nms-fetch.js | |
parent | 09710c061d5b8ae86b3dfe49f4b8936c13a10535 (diff) |
Diffstat (limited to 'web/js/nms-fetch.js')
-rw-r--r-- | web/js/nms-fetch.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/web/js/nms-fetch.js b/web/js/nms-fetch.js new file mode 100644 index 0000000..da2162c --- /dev/null +++ b/web/js/nms-fetch.js @@ -0,0 +1,38 @@ +async function getData(url) { + var data; + const request = new Request(url, { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + }); + + await fetch(request) + .then((response) => response.json()) + .then((json) => { + data = json; + }) + .catch(console.error); + + return data; +} + +async function postData(url, data) { + var data; + const request = new Request(url, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(data) + }); + + await fetch(request) + .then((response) => response.json()) + .then((json) => { + data = json; + }) + .catch(console.error); + + return data; +} |