Malý repozitář pro WTL 3.I 2025/2026
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.
 
 
 

38 lines
1.4 KiB

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pokémon API tester</title>
</head>
<body>
<h1>Pokémon API tester</h1>
<a href="index.html">Domů</a><br>
<input type="text" id="pokemonName">
<button onclick="fetchData()">Fetch Pokémon</button>
<img src="" alt="Pokemon Sprite" id="pokemonSprite" style="display: none;">
<script>
var pokejson;
const imgElement = document.getElementById("pokemonSprite")
function fetchData() {
const pokemonName = document.getElementById("pokemonName").value.toLowerCase();
const ajax = new XMLHttpRequest;
const url = `https://pokeapi.co/api/v2/pokemon/${pokemonName}`;
console.log(url)
ajax.open("GET",url,true);
ajax.onreadystatechange = function(){
if(this.status === 200 && this.readyState === 4){
pokejson = JSON.parse(this.responseText);
console.log(pokejson);
//const pokeSprite = pokejson.sprites.front_default;
const pokeSprite = pokejson.sprites.other["official-artwork"].front_default;
imgElement.src = pokeSprite
imgElement.style.display = "block";
}
};
ajax.send();
}
</script>
</body>
</html>