Refactor Pokémon data fetching and validation logic; improve error handling and logging

This commit is contained in:
vista-man
2025-03-26 10:25:08 +01:00
parent 6e06965bc0
commit 5b4fcda9d6
4 changed files with 202 additions and 14 deletions

View File

@@ -28,8 +28,10 @@ document.addEventListener("DOMContentLoaded", () => {
function fetchPokemons() {
console.log("Fetching Pokémon data from server...");
fetch(`./get-pokemon.php`)
.then((response) => response.json())
.then((data) => {
.then((response) => response.text())
.then((text) => {
console.log("Server response:", text);
const data = JSON.parse(text);
if (Array.isArray(data)) {
allPokemons = data;
localStorage.setItem("pokemons", JSON.stringify(allPokemons));