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.
| The code is as follows: |
Copy code |
<Script> $ (Function (){ SetInterval (aa, 10 ); Function aa (){ $ ("# Aa"). append ("fdsadfsa "); } }) </Script> |
Example 2
| The code is as follows: |
Copy code |
<Head> <Script src = "jQuery/jquery-1.4.1.min.js" type = "text/javascript"> </script> <Script> $ (Document). ready (function (){ SetInterval ("startRequest ()", 1000 ); }); Function startRequest () { $ ("# Date"). text (new Date (). toString ()); } </Script> </Head> |
Example 3 Let's take a look at how this refreshing method is implemented.
The ajax code for jsp pages is as follows:
| The code is as follows: |
Copy code |
$ ("# 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" pai.html (dates); // The 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.