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