Parallel Ajax Calls in Javascript/jQuery

前端 未结 9 1671
感情败类
感情败类 2021-02-07 17:18

I am completely new to Javascript/jquery world and need some help. Right now, I am writing one html page where I have to make 5 different Ajax calls to get the data to plot grap

9条回答
  •  孤城傲影
    2021-02-07 17:54

    You can't do that using async: false - the code executes synchronously, as you already know (i.e. an operation won't start until the previous one has finished).
    You will want to set async: true (or just omit it - by default it's true). Then define a callback function for each AJAX call. Inside each callback, add the received data to an array. Then, check whether all the data has been loaded (arrayOfJsonObjects.length == 5). If it has, call a function to do whatever you want with the data.

提交回复
热议问题