Right now I have this jquery:
$(".updatetwo").click(function () {
$('div.result').load('permissions.php);
});
I wanted to know, how could I .load the php every 3 seconds instead of on click?
var handler= window.setInterval(function(){
jQuery('div.result').load('permissions.php');
},3000);
if you plan to stop loading data, you can clear the handler
window.clearInterval(handler);
--
window.setInterval(code,delay)
, setInterval
executes any code
after mentioned delay
in milliseconds.
Try this
setInterval(function(){
$('div.result').load('permissions.php');
},3000);
setInterval(function () {
$('div.result').load('permissions.php');
}, 3000);
An alternative to using setInterval
, is using setTimeout
in a tail recursive fashion. This way, your function will be called approximately * 3000 ms after the previous call.
(function loadPermissions() {
jQuery('div.result').load('permissions.php');
setTimeout(loadPermissions, 3000);
})();
* I say approximately, since neither setInterval
or setTimeout
are an exact science. The delay will be as close as possible to the set delay, but because the browser takes care of drawing and executing scripts in a blocking fashion, you can't set your clock based on this.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.