
joaquin dati
PreguntaBuenas, en la consola me aparece un error “GET file:///C:/Users/Paty/Desktop/Consumoapi/undefined net::ERR_FILE_NOT_FOUND”
noto que desaparece cuando borro !==200 del segundo if pero eso hace que no me carguen las fotos en favoritos. Dejo mi codigo:
const API_URL_RANDOM = 'https://api.thedogapi.com/v1/images/search?limit=5&api_key=f507052c-c225-41b9-b06a-722c432305aa'; const API_URL_FAVORITES = 'https://api.thedogapi.com/v1/favourites?limit=5&api_key=f507052c-c225-41b9-b06a-722c432305aa'; const spanError = document.getElementById('error') async function loadRandomDogs() { const res = await fetch(API_URL_RANDOM); const data = await res.json(); console.log('Random') console.log(data) if (res.status !== 200) { spanError.innerHTML = "Hubo un error: " + res.status; } else { const img1 = document.getElementById('img1'); const img2 = document.getElementById('img2'); const img3 = document.getElementById('img3'); const btn1 = document.getElementById('btn1'); const btn2 = document.getElementById('btn2'); const btn3 = document.getElementById('btn3'); img1.src = data[0].url; img2.src = data[1].url; img3.src = data[2].url; btn1.onclick = () => saveFavouriteDogs(data[0].id); btn2.onclick = () => saveFavouriteDogs(data[1].id); btn3.onclick = () => saveFavouriteDogs(data[2].id); } } async function loadFavouriteDogs() { const res = await fetch(API_URL_FAVORITES); const data = await res.json(); console.log('Favoritos') console.log(data) if (res.status !== 200) { spanError.innerHTML = "Hubo un error: " + res.status; } else { data.forEach(puppy => { const section = document.getElementById('favoritesPuppy') const article = document.createElement('article'); const img = document.createElement('img'); const btn = document.createElement('button'); const btnText = document.createTextNode('Sacar al Puppy de favoritos'); img.src = puppy.image.url; img.width = 150; btn.appendChild(btnText); article.appendChild(img); article.appendChild(btn); section.appendChild(article); }); } } async function saveFavouriteDogs(id) { const res = await fetch(API_URL_FAVORITES, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ image_id: id }), }); const data = await res.json(); console.log('Save') console.log(res) if (res.status !== 200) { spanError.innerHTML = "Hubo un error" + res.status + data.message; } } loadRandomDogs(); loadFavouriteDogs();

Juan Castro
Cómo tienes tu código HTML?