开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜