I need to return a value of a request made with Javascript FetchAPI for a variable, I made that attempt but without success:
function listeItens(tipo_item)
{
var itens;
fetch('ajax/html/liste_itens.asp?tipo_item='+tipo_item)
.then(response =>response.text())
.then((data)=>{
itens = data;
console.log(itens); // AQUI LISTA NORMALMENTE O RETORNO
})
.catch(err => console.log(err));
console.log(itens); // AQUI LISTA undefined
return itens;
}
I wonder if there's a way to do this?