26 lines
697 B
JavaScript
26 lines
697 B
JavaScript
document.addEventListener("DOMContentLoaded", () => {
|
|
async function getData() {
|
|
const url = "http://127.0.0.1:8000/items";
|
|
console.log("Start fetching...");
|
|
try {
|
|
const response = await fetch(url, {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({ text: "example" }),
|
|
});
|
|
if (!response.ok) {
|
|
console.log(`Response status: ${response.status}`);
|
|
throw new Error(`Response status: ${response.status}`);
|
|
}
|
|
|
|
const result = await response.json();
|
|
console.log(result);
|
|
} catch (error) {
|
|
console.error(error.message);
|
|
}
|
|
}
|
|
|
|
getData();
|
|
});
|