function bookSearch() {
var search = document.getElementById('search').value
document.getElementById('results').innerHTML = ""
console.log(search)
var startIndex =
I have a requirement to continuously make Ajax calls to display all the items instead of just the first 10. By using the maxresults
parameter, we can fetch 40 items at a time. This requires updating the startIndex value from 0 to 20 to 40 and so on after each iteration.
while (startIndex < 2000) {
$.ajax({
url: "https://www.googleapis.com/books/v1/volumes?q=" + search + "&startIndex=" + startIndex + "&maxResults=40",
dataType: "json",
success: function (data) {
console.log(data)
for (i = 0; i < data.items.length; i++) {
results.innerHTML += "<h2>" + data.items[i].volumeInfo.title + "</h2>"
results.innerHTML += "<h2>" + data.items[i].volumeInfo.authors + "</h2>"
results.innerHTML += "<h2>" + data.items[i].volumeInfo.publishedDate + "</h2>"
}
},
type: 'GET'
});
}
}
document.getElementById('button').addEventListener('click', bookSearch, false)