Combining fetch and the Promise all Method

preview_player
Показать описание
When you use fetch( ) to make your AJAX calls, you will be returned a Promise object. That is why we use then( ) and catch( ) with fetch( ).
This video covers the process of how to make your page wait for all the files to be returned.

Рекомендации по теме
Комментарии
Автор

Great explanation on how to handle the response promise and making sure people see it's not a json you get back, very easy to implement Steve!

juniordallagnolo
Автор

Thank you! Your video is clear, succinct, and it solves a problem I’ve been struggling with for while. I wish I could hit the like button 100 times.

abeechr
Автор

Thank you! This video helped solve a problem that I was struggling with for a bit.

KattanaL
Автор

You make it look so easy, Steve! Thanks for the video.

rebelmachine
Автор

Your code for Promise.all is not working correctly. If you try to access the data it is a promise .. which was never resolved.

azamsharp
Автор

Thank you for providing a gist for this.

AmenRa
Автор

What if both fetch files have the same object name? They will show duplicates within the dom.

thebeat
Автор

Can this work in react, for example, in the componentWillMount method?


For some reason, the callback 'process' doesn't pause the flow of execution for me. It skips over the first json and keeps going.

alexv
Автор

This is probably a poor practice, but I need to get the both json's at the same time, so I end up nesting another Promise.all() inside the first callback function, that makes me able to combine the final result.

thanks for the video!

AlexSanchezMorales
Автор

How should we achieve the aggregation of data from 2 promises?

AjaySingh-xdnz
Автор

how to store that data in localstorage and then make a callback to display the data

i have to display this data in different way that why i am asking how to store this data in localstorage

mirsahib
Автор

I was trying to iterate over promises inside an array of images as blobs.
I tried the same approach as when using .json() and the second .then() was returning undefined for .blob().
Turns out I had to resolve the blob promise instead of chaining another .then.
This helped me out a lot.

Here's an example for anyone doing something similar.

Promise.all(imgPromises)
.then(images => {
images.forEach(res => {
res.blob().then(blobObj =>
})
})

JustLookA
Автор

Hi.. would you please able to show a demo on multiple api calls like one api call brings an array of values as response and hitting another api with the first api response data and getting final result as array.

mtcindianutube
Автор

Thanks, I fetch 3 times and concat the array =)), then Steve make me realize there have Promise all

minercreepmc