Hi I have an ajax call which filters the files in a folder. The result of the amount of files to be filtered is quite large (around 600 files). Therefore the code after the ajax call is proceeding even if the ajax call has not finished yet. Any idea how I can fix it?
function getImages() {
var allImages = [];
var top = [];
var bottom = [];
var folder = "SourceImages/";
$.ajax({
url: folder,
success: function(data) {
$(data).find("a").attr("href", function(i, val) {
if (val.match(/\.(tif)$/) && val.toLowerCase().startsWith(regId.toLowerCase()) && (!val.includes("BOUND"))) { //see how to include BOUND as well
allImages.push(val);
}else if(val.toLowerCase().startsWith(regId.toLowerCase()) && val.includes("BOUND_TOP")){
top.push(val);
}else if(val.toLowerCase().startsWith(regId.toLowerCase()) && val.includes("BOUND_BOTTOM")){
bottom.push(val);
}
});
}
});
top.sort();
bottom.sort();
allImages.sort();