I have an application that needs to make 50 to 100 API calls in a loop. Rotten tomatoes have a limit of 10 calls per second. As a result of this, my queries fail between them, and each time I get different results. What is the efficient way to make these 50 queries without exceeding the limit of 10 times / second? Here is my code:
$.each(elem, function (index, item) {
var $placeholder = $('<div>').appendTo("div.content");
$.ajax({
type: 'post' ,
url: moviesSearchUrl + '&q=' + encodeURI(item) + '&page_limit=1',
dataType: "jsonp",
async: false,
success: searchCallback
});
function searchCallback(data) {
var movies = data.movies;
var markup = index + ': '+ movies[0].title + '<img class=" bord" src="' + movies[0].posters.thumbnail + '" /><br/>';
$placeholder.replaceWith(markup);
}
});
source
share