Parallel Ajax Calls in Javascript/jQuery

前端 未结 9 2122
甜味超标
甜味超标 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:09

    Using jQuery.when (deferreds):

    $.when( $.ajax("/req1"), $.ajax("/req2"), $.ajax("/req3") ).then(function(resp1, resp2, resp3){ 
        // plot graph using data from resp1, resp2 & resp3 
    });
    

    callback function only called when all 3 ajax calls are completed.

提交回复
热议问题