I am trying to skip a loop iteration based on the ajax response. The problem I'm facing is that I'm unable to use the response from Ajax outside the
Ajax call. Currently I solved it by using the below solution but here the problem is that I'm using async: false which is not recommended as Ajax call is async.
function ajaxCallHere(name) {
let url = '/admin/someUrl/' + name;
var skipName = '';
$.ajax({
'url': url,
'type': 'GET',
async: false,
'success': function (data) {
skipName = data.skip;
}
});
return skipName;
}
function getAllNames() {
for (let i = 0; i < names.length; i++) {
var skipVal = ajaxCallHere(names.fullName);
if(skipVal == 'yes') {
continue;
}
}
}