weixin_33749242 2019-12-12 17:53 采纳率: 0%
浏览 12

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();
  • 写回答

0条回答 默认 最新

    报告相同问题?