如何安排AJAX调用每隔N秒?每隔、AJAX

由网友(如梦亦如幻)分享简介:如果我想整个页面重新加载每隔N秒,我会把这样的事情在HTML:META HTTP-当量=刷新内容=5 If I want a whole page to reload every N seconds, I would put something like this in the HTML:meta http-equ...

如果我想整个页面重新加载每隔N秒,我会把这样的事情在HTML: META HTTP-当量=刷新内容=5

If I want a whole page to reload every N seconds, I would put something like this in the HTML: meta http-equiv="refresh" content="5"

有没有做同样的事情AJAX调用一个标准的做法?我想安排一个AJAX调用熄灭每隔10秒说,以更新页面的部分,而无需刷新整个页面。它甚至会更好,如果我能安排多个AJAX在不同的时间要求,作为页面的某些部分可能需要更频繁地更新比其他人。

Is there a standard practice for doing the same kind of thing for AJAX calls? I want schedule an AJAX call to go off every 10 seconds say, in order to update parts of the page, without refreshing the whole page. It would be even better if I could schedule multiple AJAX calls at different times, as some parts of the page may need to be updated more often than others.

TIA

推荐答案

您可以使用 的setTimeout 的setInterval (后者可能是最适合你想做的事)。

You could use setTimeout or setInterval (the latter is probably best suited to what you want to do).

setInterval(makeRequest, (10 * 1000));

...其中, makeRequest 是一个函数,重新加载通过AJAX一些内容。

...where makeRequest is a function that reloads some content via AJAX.

阅读全文

相关推荐

最新文章