function getLogin(){
var login = new XMLHttpRequest();
let res; // variable
login.open('POST', 'assets/php/get_player.php', true);
login.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
login.send();
login.onreadystatechange = function() {
if (login.readyState == 4) {
if(login.status == 200) {
res = login.responseText; //Here the variable changes
}
}
}
return res
}
startbtn.forEach((button) => {
button.addEventListener('click', (e) => {
if (getLogin() == "true"){ // Here it gives undefined
}else{
alert("Вы не вошли в свой аккаунт!");
}
})
});
The 'res' variable changes, but 'return' returns undefined Here is a code that does not work Here is a code that does not work