1

I have a method in Javascript/jQuery that takes two arguments:

makeTwoChart(arrOne, arrTwo)

I am trying to call two API endpints together and pass their response in this method.

both API endpoints are returning arrays of the same length in response.

   let arrOne = [];
   let arrTwo = [];
    $.get(`${API_URL}tour/month-wise-product/`, function(data, status) {
        arrOne=data.results
        
    });


    $.get(`${API_URL}tour/month-wise-sell/`, function(data, status) {
        arrTwo=data.results
    });

   makeTwoChart(arrOne, arrTwo)

I am not getting what to do in this situation, Can anyone help me in this situation? How to send two response in method at the same you get a response

Can anyone help me in this case?

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
  • 1. [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call); 2. Use [`$.when()`](https://api.jquery.com/jquery.when) – Andreas Oct 03 '20 at 10:51

1 Answers1

0

You can use .when()

let arrOne = [];
let arrTwo = [];
$.when(
        $.get(`${API_URL}tour/month-wise-product/`),
        $.get(`${API_URL}tour/month-wise-sell/`)
).then(function(resp1, resp2))
Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175