Ajax realizes page automatic flash-free refresh instance parsing

default-user-image.png

Here’s an introduction to jQuery’s implementation of AJAX timing partial page refresh

From time to time, I need some kind of mechanism that constantly refreshes the page to provide a real-time dashboard of some sort. It would be great if I could only refresh a specific part of the page, eg: a traffic light on the dashboard showing the system status.

This is very easy by using the jQuery JavaScript library to refresh only part of the page. Once we incorporate the jQuery library into our page, we only need 1 line of JavaScript to get it to work:

 <script src="/js/jquery-1.3.2.min.js" type="text/javascript"></script>

So we just put this little JS snippet into our page to refresh everything inside the content ID tag, let’s say every 5 seconds:

 setInterval(function() {     $("#content").load(location.href+" #content>*","");   }, 5000);

This is it! ! So it’s easy to do some real-time monitoring behavior with just that line of code. No more weird meta refresh tags or iframes as a workaround in a web app.

Every 5 seconds, we will refresh the URL and all elements with the same content, residing in the element with the element ID of content:content.

This article is reprinted from https://blog.p2hp.com/archives/8557
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment