I have the following code that works perfectly other than the fact that it has to use async false, to wait for a response from ajax. Is there a way of restructuring this by using callbacks, or deferment?
playbtn.on('mousedown', function () { // functions when clicking play button
function checkUser() {
$.ajax({
url: "/submit/checkuser/",
async: false,
success: function (userStatus) {
if (userStatus == 'Disabled') { // check if user if disabled
if (Shadowbox.isOpen()) {
Shadowbox.close(); setTimeout(function () { accountDisabled(); }, 750);
} else {
Shadowbox.clearCache(); accountDisabled();
};
setTimeout(function () { location.replace('/'); }, 10000);
} else if (userStatus == 'Deleted') { // check if user if deleted
if (Shadowbox.isOpen()) {
Shadowbox.close(); setTimeout(function () { accountDeleted(); }, 750);
} else {
Shadowbox.clearCache(); accountDeleted();
};
setTimeout(function () { location.replace('/'); }, 10000);
} else {
Shadowbox.setup();
};
},
error: function (e) {
if (e.status != 403) {
if (!Shadowbox.isOpen()) {
Shadowbox.clearCache(); connectionError();
};
};
},
statusCode: {
403: function () {
if (Shadowbox.isOpen()) {
Shadowbox.close(); setTimeout(function () { locationNotAuthorized(); }, 750);
} else {
Shadowbox.clearCache(); locationNotAuthorized();
};
}
}
});
};
Shadowbox.clearCache(); // disable shadowbox to check user status
checkUserTimer = setInterval(function () { checkUser(); }, 600000);
checkUser();
});