I have an application which has 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 requests fail in between and i get different results everytime. What is an effective way to make these 50 requests without exceeding the 10 reqs/per second limit ? Here's 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);
}
});