You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
914 B
27 lines
914 B
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 = `<p><b>${data.id}</b>
|
|
- ${data.title}
|
|
- ${data.completed ? "Hotovo":"Nedokončen</p>"}`
|
|
}else{
|
|
todoResult.innerHTML = "<p>Úkol nenalezen</p>"
|
|
}
|
|
}).catch(error => {
|
|
console.error("Chyba při našítaní dat:",error);
|
|
todoResult.innerHTML = "<h2>Chyba při načítání dat</h2>"
|
|
})
|
|
|
|
|
|
|
|
|
|
})
|