Parallel Ajax Calls in Javascript/jQuery

前端 未结 9 2126
甜味超标
甜味超标 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 17:52

    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.

提交回复
热议问题