Answer the question
In order to leave comments, you need to log in
How to execute an AJAX request with a delay?
I work with API Vkontakte. It is necessary to send vk requests and receive a response. I do it all in a loop. However, because there is a limit on the number of requests per second, some requests receive the "Too many requests" error. The process is periodic, since it all happens in a cycle. How to implement sending a request every 0.3 seconds.
Answer the question
In order to leave comments, you need to log in
We pack the script with the ajax request into a function. After each successful completion of the request, we run setTimeout ( not setInterval ! ) and call our function again after N seconds.
function myAjax() {
$.ajax({
/* прочие опции*/
,
success: function() {
setTimeout(myAjax, 5000);
}
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question