Click here to Skip to main content
14,983,982 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working with asynchronous javascript and am having the hardest time figuring out how to do this:

When I send a get request to [a star wars data site], it returns an object that has a key called results, which has a value of each film and all of the data, including an array of planets. The tricky part is the array of planets are only more links to the API that need ajax requests for data.



I need to loop through the array of planets for each movie and make more AJAX calls to collect the name of each planet, organized by film. Then, console log an array of objects in which each object contains the opening crawl for a specific movie, along with the names of every planet featured in that movie.

What I have tried:

So far I have finished a function that can console log opening_crawls. I am honestly unsure where to start with this issue? Do I need to use promise.all? I am just learning about async code.
Posted
Updated 26-Mar-18 19:46pm
v2
Comments
OriginalGriff 27-Mar-18 1:47am
   
I removed the badly-formed link that you inserted: I don't think you intended to post spam, but that was very much what it looked like.
Richard Deeming 27-Mar-18 7:29am
   
You probably want to look at the Fetch API[^] (and the polyfill[^] for older browsers), combined with Promise.all[^] (and the polyfill[^]).

If you can drop support for IE, or use an ES5 transpiler, you might find it simpler to use an async function[^].

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900