function verifyDeleteFacilitator(facilitatorId, handleData) {
var request = $.ajax({
type: 'GET',
url: urls.verifydeletefacilitator,
data:{facilitatorId: facilitatorId}
}).done(function (response) {
return handleData(response);
})
}
var deleteButtonText = "";
verifyDeleteFacilitator(facilitator.value, function (canBeDeleted) {
console.log(canBeDeleted);
if (canBeDeleted == true) {
deleteButtonText = '<button class="badge btn-danger p-2" id="confirmDeleteFacilitator" type="button"><i class="fas fa-exclamation-triangle"></i>Confirm Deletion</button>';
}
})
console.log(deleteButtonText);
The issue with canDeleteText not being set properly lies in the scope of the callback function. Here is how you could correct it: