Parallel Ajax Calls in Javascript/jQuery

前端 未结 9 1667
感情败类
感情败类 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 18:01

    It looks like you need to dispatch your request asynchronously and define a callback function to get the response.

    The way you did, it'll wait until the variable is successfully assigned (meaning: the response has just arrived) until it proceeds to dispatch the next request. Just use something like this.

    $.ajax({
      url: url,
      dataType: 'json',
      data: data,
      success: function(data) {
         area0Obj = data;
      }
    });
    

    This should do the trick.

提交回复
热议问题