Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript AJAX Basics (retiring) AJAX and APIs Stage 4 Challenge Answer

How do I limit the search to let's say 5 or 10 images displayed?

I want to control my program so it displays the exact number of images I want. Also, can someone point me to the good resource to learn to add "loading" wheel when user waits for the AJAX response to happen.

Thanks!

1 Answer

Steven Parker
Steven Parker
231,275 Points

When you display the results, instead of using ".each" to create an element for every image, use another kind of loop where you can specify a limit on the iterations. Or use "slice" to get a subset of "data.items" and run "$.each" on that.

Ans you can easily find "loading animations" or "spinners" with any search engine. Here's a collection of several I spotted in a quick search that are implemented using CSS animations: Loaders and Spinners. Typically, you would display the spinner when you submit the AJAX request, and then hide it when you display request results.