Parallel Ajax Calls in Javascript/jQuery

前端 未结 9 2127
甜味超标
甜味超标 2021-02-07 17:26

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 18:08

    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.

提交回复
热议问题