Ajax在继续之前先完成

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();
查看全部
weixin_33749242
weixin_33749242
2019/12/12 17:53
  • ajax
  • 点赞
  • 收藏
  • 回答
    私信

0个回复