Example of jQuery regular partial refresh

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.