JavaScript AJAX Basics (retiring) AJAX and APIs Displaying the Photos

Przemyslaw Mazur
PRO
Przemyslaw Mazur
Pro Student 9,296 Points

Why this code works ?

My question is why the displayPhotos function works before $.getJSON runs?

1 Answer

I Dilate
I Dilate
3,979 Points

$.getJSON sends a request to a server, which is likely to be slower returning than the time that the rest of the code in your script takes to be executed.

Remember a few lessons back, you were told that AJAX queries return at different times, and you can't predict which one comes back first? This is a good example.

Note: your question was a little vague - this is the best I can do to answer it without you providing more information. If you're experiencing a specific problem with this challenge, can you elaborate please?

I Dilate
I Dilate
3,979 Points

Note, that the A in AJAX stands for "Asynchronous" - and this is exactly what it means.