如何在特定时间段内调用Ajax请求? 我应该使用Timer插件还是jQuery有一个插件?调用jQuery Ajax请求每个X分钟
回答
您可以使用内置的javascript setInterval。
var ajax_call = function() {
//your jQuery ajax code
};
var interval = 1000 * 60 * X; // where X is your every X minutes
setInterval(ajax_call, interval);
,或者如果你是更简洁型...
setInterval(function() {
//your jQuery ajax code
}, 1000 * 60 * X); // where X is your every X minutes
你有几个选项,你可以setTimeout()
或setInterval()
。 Here's a great article that elaborates on how to use them。
神奇的是,它们内置于JavaScript中,您可以将它们与任何库一起使用。
没有普金要求。你只能使用jQuery的。
如果你想设置的东西在一个计时器,你可以使用JavaScript的setTimeout
或setInterval
方法:
setTimeout (expression, timeout);
setInterval (expression, interval)
;
setinterval实际上来自javascript而不是jquery。 – 2013-05-16 04:57:29
你可以在JavaScript中使用setInterval()
<script>
//Call the yourAjaxCall() function every 1000 millisecond
setInterval("yourAjaxCall()",1000);
function yourAjaxCall(){...}
</script>
使用jQuery Every time Plugin。采用这个你可以做的Ajax调用的 “X” 时间段
$("#select").everyTime(1000,function(i) {
//ajax call
}
你也可以使用的setInterval
_everytime_的链接被破坏... – nbro 2016-07-21 09:05:23
有点晚了,但我用jQuery ajax方法。但是,如果我没有收到最后一次请求的回复,我不想每秒发送一次请求,所以我这样做了。
function request(){
if(response == true){
// This makes it unable to send a new request
// unless you get response from last request
response = false;
var req = $.ajax({
type:"post",
url:"request-handler.php",
data:{data:"Hello World"}
});
req.done(function(){
console.log("Request successful!");
// This makes it able to send new request on the next interval
response = true;
});
}
setTimeout(request(),1000);
}
request();
我发现了一个非常好的jQuery插件,可以用这种类型的操作来缓解你的生活。您可以结帐https://github.com/ocombe/jQuery-keepAlive。
$.fn.keepAlive({url: 'your-route/filename', timer: 'time'}, function(response) {
console.log(response);
});//
- 1. 每2分钟用robospice执行请求
- 2. 调用PHP函数每隔x分钟
- 3. 每x分钟调用一次方法
- 4. 如何限制每个用户每分钟的请求数?
- 5. 每隔X分钟向我发送一次HTTP GET请求
- 6. jquery ajax请求在每个请求上呈指数级增长
- 7. 在由时钟每“X”分钟
- 8. Glassfish:限制用户每秒/每分钟的请求数量
- 9. jquery AJAX请求
- 10. Ajax请求中的jQuery Ajax请求
- 11. jquery ajax多个请求
- 12. 多个Ajax请求 - jQuery
- 13. 调用rich:modalPanel对于每个使用a4j:status的ajax请求?
- 14. jQuery ajax请求:按请求顺序调用的成功函数
- 15. C# - 调度一个任务,每X分钟运行
- 16. jQuery Ajax - 每个请求的备用XML源码
- 17. 如何在每个ajax或完整请求后调用javascript
- 18. 运行JavaScript命令每隔X分钟
- 19. 用jquery超时Ajax请求?
- 20. 使用jQuery的AJAX请求
- 21. jquery Ajax多用户请求
- 22. ASP.NET - 用jQuery Ajax请求
- 23. RxJS:每秒发送x个请求
- 24. jquery,如何使用多个Ajax请求?
- 25. 使用jQuery AJAX使得两个请求
- 26. 与jQuery Ajax请求
- 27. Loopback jQuery AJAX请求
- 28. Symfony jQuery ajax请求
- 29. jquery mouseleave ajax请求
- 30. JQuery的AJAX请求
你可以谷歌这个。 http://stackoverflow.com/questions/4542863/jquery-ajax-call-with-timer – Zabba 2011-02-08 07:06:39
你做了什么? – PinoyStackOverflower 2013-07-17 05:44:51