My application needs to make 50 to 100 API calls in a loop, but Rotten Tomatoes has a limit of 10 calls per second. As a result, my requests fail and I get different results each time. How can I effectively make these 50 requests without exceeding the 10 reqs/per second limit? Here is the current code snippet:
$.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);
}
});