get notes added

This commit is contained in:
ed barz 2023-05-25 16:35:43 +02:00
parent 4400cbc69e
commit 96d26ce568
1 changed files with 24 additions and 1 deletions

View File

@ -19,6 +19,21 @@
alert('Failed to create note');
}
}
let notes = [];
async function fetchNotes() {
const response = await fetch('http://localhost:8069/notes');
if (response.ok) {
notes = await response.json();
} else {
console.error('Failed to fetch notes');
}
}
// Fetch notes when the component is first rendered
fetchNotes();
</script>
@ -32,4 +47,12 @@
</ul>
<input bind:value={text} type="text" placeholder="Enter note text" />
<button on:click={createNote}>Create Note</button>
<button on:click={createNote}>Create Note</button>
<button on:click={fetchNotes}>Refresh Notes</button>
<ul>
{#each notes as note}
<li>{note.Text}</li>
{/each}
</ul>