delay ajax request
What is the best way to set timeout that will force my page no开发者_运维知识库t to set more than one ajax request per minute
Thanks in advance!
I'd use a simple variable holding the timerId returned from setTimeout. Something like this:
var timerId;
var doRequest = function(){
if(timerId) return;
timerId = setTimeout(doRequest, 60*1000);
// ajax code here
};
This will throttle the request to once per minute. If you need to stop the setTimeout call, then simply add another boolean based off the user event you are watching for.
精彩评论