JQuery implements regular AJAX refreshing of partial page instances, jqueryajax
Method 1:
Partial Refresh: ajax is the most talked about. Of course, ajax is not used to refresh the page. We can use the append in jquery to add something to the specified content, of course, ajax loads data.
Example: timed partial refresh
The setInterval method in jQuery is used for timed partial refresh. The setInterval method has two parameters: the first is to set the name of the function to be scheduled, and the second is the time, as shown in the following code, set to execute the aa method at intervals of 10 microseconds.
<script>$(function(){ setInterval(aa,10); function aa(){ $("#aa").append("fdsadfsa"); }})</script>
Example 2
Example 3 let's take a look at how this refreshing method is implemented.
Jsp page ajax
$ ("# WaitWork "). click (function () {var url = "request address"; var data = {type: 1}; $. ajax ({type: "get", async: false, // synchronous request url: url, data: data, timeout: 1000, success: function (dates) {// alert (dates); $ ("# mainContent" ).html (dates); // div to be refreshed}, error: function () {// alert ("failed, please try again later! ");}});});
Html
<div id="mainContent">
Note: The background must use a single jsp page for the information in the div. Otherwise, you must encapsulate the required page information and return it.
Method 2:
From time to time, I need a mechanism to constantly refresh webpages to provide a real-time dashboard. If I can only refresh a part of a specific page, it will be very large. For example, the traffic light on the dashboard shows the system status.
It is easy to use the jQuery JavaScript library to refresh only part of the page. Once we include the jQuery library of our page, we only need one line
JavaScript gets its work:
<script src="/js/jquery-1.3.2.min.js" type="text/javascript"></script>
So as long as we put this small JS code snippet into our page to refresh everything in the Content ID tag, let's say every 5 seconds:
setInterval(function() { $("#content").load(location.href+" #content>*","");}, 5000);
This is it !! Therefore, it is easy to complete some real-time monitoring behaviors, just that line of code. No more strange metadata refresh tag or iframe is a solution in Web applications.
Every 5 seconds, we will refresh the URL with the same content and all elements, resident in the content where the element ID is the content element: content.