POSTing the body to the server.
This commit is contained in:
parent
91e9645c37
commit
c24c5ee54e
@ -1,5 +1,13 @@
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<script type="text/javascript" src="script.js" defer></script>
|
||||
</head>
|
||||
<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>
|
||||
</html>
|
||||
|
35
static/script.js
Normal file
35
static/script.js
Normal 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
0
static/style.css
Normal file
Loading…
Reference in New Issue
Block a user