My function fetches if the user is banned and i want to return a variable that determines if a popup displays; but as I've found out you can't return a variable from a getJSON function.
function fetchban() {
$.getJSON('/fetchban.php',function(data) {
if(data==0) {
var banned = data;
} else {
$.each(data,function(index,result) {
$('#ban-prompt').html(result);
$('.popup-background').show();
$('#ban-container-2').show();
});
}
});
return banned;
}
$('.button').click(function() {
var banned = fetchban();
if(banned==0) {
//display-popup
}
});
There are alot of lines i call the fetchban function, so i would prefer the getJSON in a function. What is the solution?