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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Matlab问题解答有两个问题
    • ¥50 Oracle Kubernetes服务器集群主节点无法访问,工作节点可以访问
    • ¥15 LCD12864中文显示
    • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
    • ¥15 gsoap生成onvif框架
    • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。
    • ¥15 stm32的can接口不能收发数据
    • ¥15 目标检测算法移植到arm开发板
    • ¥15 利用JD51设计温度报警系统
    • ¥15 快手联盟怎么快速的跑出建立模型