jQuery 你如何在jquery中设置ajax调用的间隔
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17529783/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 19:15:07 来源:igfitidea点击:
how do you set interval to ajax call in jquery
提问by user1471980
I need to create an ajax call every 5 minutes. I have to below code. Can someone tell me how would I modify this code to run that ajax every 5 minutes?
我需要每 5 分钟创建一个 ajax 调用。我必须在下面的代码。有人可以告诉我如何修改此代码以每 5 分钟运行一次 ajax 吗?
$(document).ready(function() {
var seriesOptions = [],
yAxisOptions = [],
colors = Highcharts.getOptions().colors;
$.ajax({
url: 'echo_file.php',
datatype: 'json',
success: function(data) {
seriesOptions=data;
createChart();
},
cache: false
});
function createChart() {
.
.
.
}
});
回答by tymeJV
At the simplest level, put your AJAX call into a function, then create an interval:
在最简单的层面上,将您的 AJAX 调用放入一个函数中,然后创建一个间隔:
setInterval(ajaxCall, 300000); //300000 MS == 5 minutes
function ajaxCall() {
//do your AJAX stuff here
}