May 2017
Intermediate to advanced
448 pages
10h 10m
English
By now, we are experts at the common task of reacting to a click on a page element. When the More Photos link is clicked on, we need to perform an Ajax request for the next set of photos and append them to <div id="gallery"> as follows:
$(() => { $('#more-photos') .click((e) => { e.preventDefault(); const url = $(e.target).attr('href'); $.get(url) .then((data) => { $('#gallery') .append(data); }) .catch(({ statusText }) => { $('#gallery') .append(`<strong>${statusText}</strong>`) }); });});
We also need to update the destination of the More Photos link to point to the next page of photos:
$(() => { var pageNum = 1; $('#more-photos') .click((e) => { e.preventDefault(); const $link = $(e.target); ...Read now
Unlock full access