Created
March 4, 2025 17:08
-
-
Save thinkphp/639002e743d21f89a0c1b9f79a74841a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Cerere asincronă simplă | |
async function cautaProdus() { | |
// Arată că suntem în proces de încărcare | |
console.log('Se caută produsul...'); | |
try { | |
// Trimite cererea - nu blochează alte lucruri | |
const raspuns = await fetch('https://fakestoreapi.com/products/1'); | |
// Convertește răspunsul în JSON | |
const produs = await raspuns.json(); | |
// Afișează produsul | |
console.log('Produs găsit:', produs); | |
} catch (eroare) { | |
// Tratează erorile dacă ceva nu merge | |
console.error('Eroare la căutare:', eroare); | |
} | |
} | |
// Apelează funcția | |
cautaProdus(); | |
// Cod care continuă să ruleze imediat | |
console.log('Continuă alte sarcini...'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment