Flask-Notizen/templates/index.html
2024-08-25 21:25:23 +02:00

62 lines
1.9 KiB
HTML

<!DOCTYPE html>
<html lang="de">
<head>
<script>
let notesdiv;
function buttonclick() {
fetch("/note",{
method:"POST",
body: JSON.stringify(notizinput.value),
headers: {"Content-type":"application/json; charset=UTF-8"}
});
notizinput.value = "";
getnotes()
};
function getnotes() {
notesdiv.innerHTML = "";
fetch("/note", { method: "GET" })
.then(response => response.json())
.then(notesarray => {
console.log(notesarray);
for (let note of notesarray) {
console.log(note);
notesdiv.innerHTML += `
<div class="note">
<p>${note}</p>
</div>`;
}
});
}
function initstuff() {
notesdiv = document.getElementById("notes");
getnotes();
//setInterval(getnotes,10000)
}
function handleKeyPress(event) {
if (event.key === "Enter") { // Überprüfen, ob die Enter-Taste gedrückt wurde
buttonclick();
}
}
window.onload = initstuff;
</script>
<link rel="stylesheet" href="/static/style.css">
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Api Test</title>
</head>
<body id="body">
<h1>Notizen</h1>
<div onsubmit="" style="padding-bottom: 10px;" id="notizform">
<input onkeydown="handleKeyPress(event)" type="text" class="input" id="notizinput">
<button onclick="buttonclick()" class="button">hinzufügen</button>
</div>
<div id="notes"></div>
</body>
</html>