0

Want to call the api multiple url to get the data. In Select option and the card . //data.json file

<div>
  <select id="cars" name="cars">
    <option value="">${}</option>
  </select>
</div>

<!--card layout -->
<section>
  <div class="card">
    <img src=${} alt="${}" style="width:100%">
    <div class="container">
      <h4>${name}</h4>
      <p>${job.post}</p>
    </div>
  </div>
</section>
biberman
  • 5,606
  • 4
  • 11
  • 35
Siddhesh
  • 11
  • 8
  • Did you see promise.all ? Are these dependent apis or independent? – Harmandeep Singh Kalsi Jun 16 '20 at 03:25
  • @Harmandeep Singh Kalsi both independent api and dependent api it is a json file for development and testing purpose.On Load data should be in select dropdown and after the selecting the option other data should be shown in the card in multiple cards. Thanks in Advanced. – Siddhesh Jun 16 '20 at 03:33
  • onload you can call the first api and load the options in the dropdown , check this for that https://www.codebyamir.com/blog/populate-a-select-dropdown-list-with-json and there a event , onChange for select-option where you can call another api . For onchange see this . https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onchange – Harmandeep Singh Kalsi Jun 16 '20 at 03:37
  • @Harmandeep Singh Kalsi can be done in single api call using fetch-api or Async-await in pure Javascript.for both process – Siddhesh Jun 16 '20 at 03:43
  • But you are saying the second api should be called based on the option selected from the dropdown? Isn't it? . Or you want to call both APIs at once have the data with you in hand ? – Harmandeep Singh Kalsi Jun 16 '20 at 03:45
  • If that is the case please check this: https://stackoverflow.com/questions/52940818/fetching-multiple-files-using-promises-and-fetch-api-javascript – Harmandeep Singh Kalsi Jun 16 '20 at 03:47
  • @Harmandeep Singh Kalsi if possible it can be use with it in single api call a display data in card aswell as in select option.Sorry confusion. – Siddhesh Jun 16 '20 at 03:54
  • If you are making multiple calls to your api you have designed your api incorrectly. – Adrian Brand Jun 16 '20 at 04:37
  • @Adrian Brand ,what will be the correct way to design api to make multiple calls on load.Thanks in Advanced. – Siddhesh Jun 16 '20 at 05:03
  • You have and endpoint where you pass a list of list of ids and get back a list of the details rather than one at a time. Saves round trips to the server. – Adrian Brand Jun 16 '20 at 05:05

0 Answers0