jQuery time function
Hello I have this snippet of jQuery code
jQuery(document).r开发者_运维知识库eady(function($) {
$.get("<?echo $site['url'];?>modules/tuitting/tuitting_core/classes/count.php", function (data) {
var resultDiv = document.getElementById('count');
resultDiv.innerHTML = data;
});
});
Now what I need is to make this function continuosly checking the data, even when the page is not refreshing. I think I should use a jquery timing function, but I do not really know jQuery at all, and I am lost. Who is so nice to provide the code to me? That would be VERY appreciated. Thanks!
put it in a function with setTimeout
:
function repeat_get()
{
$.get("<?echo $site['url'];?>modules/tuitting/tuitting_core/classes/count.php", function (data)
{
var resultDiv = document.getElementById('count');
resultDiv.innerHTML = data;
setTimeout(repeat_get, 2000); //2 seconds
});
}
What you should do is put this on an interval:
setInterval(function()
{
$.get("<?echo $site['url'];?>modules/tuitting/tuitting_core/classes/count.php", function (data)
{
var resultDiv = document.getElementById('count');
resultDiv.innerHTML = data;
});
}, 2000);
This will invoke the callback defined every 2000 milliseconds. In your read event, you simply start the interval:
$(document).ready(function()
{
setInterval(...);
});
精彩评论