Created
March 4, 2025 17:03
-
-
Save thinkphp/d208fad30a8284e2b986e776cc8dae34 to your computer and use it in GitHub Desktop.
functie asyncrona
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
async function obtineDateUtilizator(idUtilizator) { | |
try { | |
// Folosim fetch pentru a face cererea | |
const raspuns = await fetch(`https://jsonplaceholder.typicode.com/users/${idUtilizator}`); | |
// Convertim răspunsul în format JSON | |
const date = await raspuns.json(); | |
// Afișăm datele utilizatorului | |
console.log('Date utilizator:', date); | |
return date; | |
} catch (eroare) { | |
// Gestionăm orice erori care pot apărea | |
console.error('A apărut o eroare:', eroare); | |
} | |
} | |
// Apelăm funcția | |
obtineDateUtilizator(1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment