开发者

Refresh an element in jquery

I have a anchor element o开发者_如何学运维n a page that i need to refresh every 5 seconds. It is only one anchor so i do not need a cycle plugin here.

How can I refresh the element i want without reloading the page. Any plugins?


Rather than going for any plug in Make use of setInterval() function for this kind of repeat function :

setInterval ( "doSomething()", 5000 );

function doSomething ( )
{
  // (do something here)
}

More : setInterval()


You can use the Ajax functionality in jQuery : Documentation link!

Especialy the .load() method will help.

Please note that this will only work for files located on the same server (a security measure in javaScript). I you want to pull from a remote server, you'll need a server side proxy to fetch the data.


var myIntervalId = setInterval("function_to_execute()", 5000);

This function_to_execute() will be called every 5 seconds after your page loads. You can put your refreshing code there and it will be executed every 5 seconds.

It does not refresh your page unless you explicitly refresh it inside the function_to_execute() function.

To cancel this timer, call -

clearInterval ( myIntervalId );


setInterval ( "UpdateDivID()", 5000 );

function UpdateDivID()
{

$('#AnchorID').html('Someone has refreshed the page');

}

Will change the html of the AnchorID.. Be more specific.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜