Method One:
Local refresh we are talking about Ajax, of course, we can not use Ajax to refresh the page, we can use the append in jquery to add something to the specified content, of course, the most practical Ajax loading data.
example, timed local refresh
Timed local refresh using jquery inside the SetInterval method, SetInterval method two parameters, the first is to set the function name of the timer, the second is time, as shown in the code below, set every 10 microseconds timed to perform a AA method.
<script>
$ (function () {
setinterval (aa,10);
function aa () {
$ ("#aa"). Append ("FDSADFSA");
}
)
</script>
Example 2
Example 3 Let's take a look at how this refresh method is implemented.
JSP page Ajax
$ ("#waitWork"). Click (function () {
var url = "Request Address";
var data = {Type:1};
$.ajax ({
type: "Get",
async:false,//sync request
Url:url,
data:data,
timeout:1000,
success: function (dates) {
//alert (dates);
$ ("#mainContent"). HTML (dates)//the div to be refreshed
,
error:function () {
//alert ("Failed, please try again later!"). ");
}
});
});
Html
Note: The background needs for the information div in a separate JSP page, or you need to encapsulate the required page information back
Method Two:
Sometimes, I need some kind of mechanism to keep refreshing the pages to provide a real-time dashboard. If I can only refresh a particular part of the page, it will be great, for example: the traffic lights on the dashboard show the system state.
It is easy to refresh a part of the page by using the jquery JavaScript library only. Once we've incorporated our page into the jquery library, we only need 1 lines of
JavaScript gets it's work:
<script src= "/js/jquery-1.3.2.min.js" type= "Text/javascript" ></script>
So we just put our page into this little JS code snippet to refresh the contents of the ID tag in everything, let's say, every 5 seconds:
SetInterval (function () {
$ ("#content"). Load (location.href+ "#content >*", "");
}, 5000);
That's it!! Therefore, it is very easy to complete some real-time monitoring behavior, just that line of code. No more bizarre meta refresh tags or iframe a workaround in the Web application.
Every 5 seconds, we will refresh the same URL and all elements that reside in the Content element ID: content.