POSTing the body to the server.

This commit is contained in:
Tom Alexander 2023-08-18 15:41:06 -04:00
parent 91e9645c37
commit c24c5ee54e
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 44 additions and 1 deletions

View File

@ -1,5 +1,13 @@
<html> <html>
<head>
<link rel="stylesheet" href="style.css">
<script type="text/javascript" src="script.js" defer></script>
</head>
<body> <body>
Test html file. Input org-mode source:<br/>
<textarea id="org-input" rows="24" cols="80"></textarea>
<hr/>
<div id="parse-output" class="code_block">
</div>
</body> </body>
</html> </html>

35
static/script.js Normal file
View File

@ -0,0 +1,35 @@
let inFlightRequest = null;
const inputElement = document.querySelector("#org-input");
const outputElement = document.querySelector("#parse-output");
function abortableFetch(request, options) {
const controller = new AbortController();
const signal = controller.signal;
return {
abort: () => controller.abort(),
ready: fetch(request, { ...options, signal })
};
}
async function renderParseResponse(response) {
console.log(response);
}
inputElement.addEventListener("input", async () => {
let orgSource = inputElement.value;
if (inFlightRequest != null) {
inFlightRequest.abort();
inFlightRequest = null;
}
let newRequest = abortableFetch("/parse", {
method: "POST",
cache: "no-cache",
body: orgSource,
});
inFlightRequest = newRequest;
let response = await inFlightRequest.ready;
renderParseResponse(await response.json());
});

0
static/style.css Normal file
View File