create-schematic-gen-site/site/files.js

23 lines
859 B
JavaScript
Raw Normal View History

2023-07-15 22:22:48 +00:00
const form = document.getElementById("schematic-form");
const resultContainer = document.getElementById("result-container");
2023-07-15 22:22:48 +00:00
form.onsubmit = async (e) => {
e.preventDefault();
resultContainer.innerHTML = "";
2023-07-15 22:22:48 +00:00
console.log(e);
const data = new FormData(form);
console.log(data);
try {
const response = await fetch("/extracts", {
method: "POST",
body: data
});
const result = await response.json();
const extractId = result.extractId;
const url = window.location.origin + "/extracts/" + extractId;
resultContainer.innerHTML = `<p>Copy this URL, and provide it to the computer: <em>${url}</em></p>`;
2023-07-15 22:22:48 +00:00
form.reset();
} catch (error) {
console.error("Error: " + error);
resultContainer.innerHTML = `<p>An error occurred: ${error}</p>`;
2023-07-15 22:22:48 +00:00
}
};