From cd74b8155f7c95dfbeb467757e5a8e4fac689028 Mon Sep 17 00:00:00 2001 From: KubMakCZ Date: Tue, 9 Dec 2025 09:22:38 +0100 Subject: [PATCH] api&ajax --- 20_ajax/index.html | 13 +++++++++++++ 20_ajax/pokemon.html | 38 ++++++++++++++++++++++++++++++++++++++ 20_ajax/todofetch.html | 19 +++++++++++++++++++ 20_ajax/todoscript.js | 27 +++++++++++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 20_ajax/index.html create mode 100644 20_ajax/pokemon.html create mode 100644 20_ajax/todofetch.html create mode 100644 20_ajax/todoscript.js diff --git a/20_ajax/index.html b/20_ajax/index.html new file mode 100644 index 0000000..3d2eea0 --- /dev/null +++ b/20_ajax/index.html @@ -0,0 +1,13 @@ + + + + + + Document + + +

Práce s API servery

+ Práce s Pokémon API (pokeapi.co)
+ Práce s TodoList API (jsonplaceholder.typicode.com) + + \ No newline at end of file diff --git a/20_ajax/pokemon.html b/20_ajax/pokemon.html new file mode 100644 index 0000000..49662d9 --- /dev/null +++ b/20_ajax/pokemon.html @@ -0,0 +1,38 @@ + + + + + + Pokémon API tester + + +

Pokémon API tester

+ Domů
+ + + + + + + \ No newline at end of file diff --git a/20_ajax/todofetch.html b/20_ajax/todofetch.html new file mode 100644 index 0000000..fcf01cc --- /dev/null +++ b/20_ajax/todofetch.html @@ -0,0 +1,19 @@ + + + + + + Práce s API + + +

Práce s API serverem

+ Domů
+ + +
+
+
+ + + + \ No newline at end of file diff --git a/20_ajax/todoscript.js b/20_ajax/todoscript.js new file mode 100644 index 0000000..eb93f78 --- /dev/null +++ b/20_ajax/todoscript.js @@ -0,0 +1,27 @@ +document.getElementById("fetchTodo").addEventListener("click",function(){ + const todoId = document.getElementById("todoId").value; + var todoResult = document.getElementById("todoResult"); + todoResult.innerHTML = "Načítám..." + + let url = "https://jsonplaceholder.typicode.com/todos/"; + if (todoId !== "" && todoId > 0) { url += todoId; } + console.log(url) + + fetch(url).then(response => response.json()) + .then(data => { + if(data) { + todoResult.innerHTML = `

${data.id} + - ${data.title} + - ${data.completed ? "Hotovo":"Nedokončen

"}` + }else{ + todoResult.innerHTML = "

Úkol nenalezen

" + } + }).catch(error => { + console.error("Chyba při našítaní dat:",error); + todoResult.innerHTML = "

Chyba při načítání dat

" + }) + + + + +}) \ No newline at end of file