I\'m interacting with an API that allows one action per 5 seconds. However, I want to ensure all requests end up with the host. How can I queue and throttle the requests tha
This is a shorter solution and doesn't throttle the first call put into the queue.
let ajaxQueue = [];
let ajaxQueueTime = 2000;
Execute your ajax calls like this.
requests.push(function() {
$.get(url, function(rsp) {
console.log("Hello");
});
});
This is the routine that processes the ajax call queue.
(function throttleAjax() {
if (ajaxQueue.length > 0) ajaxQueue.pop()();
setTimeout(throttleAjax, ajaxQueueTime);
})();