I have the function below that sends a fetch request and return a JSON result, I have checked the response and it does return a value that I need, return userid does return me a value, the problem is when I call this function it returns an undefined value even though I have checked it does return a value with the function.
I am looking for a simple solution.
function currentloginid() {
fetch('http://localhost/gaq/api/api.php?action=userid', {
method: 'GET',
}
)
.then(function(response) {
response.json().then(function(data) {
var userid = JSON.parse(data);
console.log(userid);
return userid;
})
})
}