Based on jquery Ajax technology to implement interval N-second to a certain page transfer value _ajax related

Source: Internet
Author: User
Tags setinterval time interval

Sometimes we need to send a value to a page every once in a while, such as a chat room, every few seconds just like the database processing page values and retrieve, and then display in the Chat window. Or, every once in a while, check if the user's last speaking time is 2 minutes apart, and if so, the user exits. This time we'll use the HTML DOM setinterval () method.

The SetInterval () method can call a function or a calculation expression in the specified period (in milliseconds).

The SetInterval () method keeps calling the function until the clearinterval () is called or the window is closed. The ID value returned by SetInterval () can be used as an argument to the Clearinterval () method.

Grammar:

Copy Code code as follows:

SetInterval (code,millisec[, "Lang"])

Code

Necessary. The function to invoke or the code string to execute.

Millisec

Have to. The time interval, in milliseconds, between the periodic execution or invocation of code.

eg

 SetInterval (function () {
      host = Window.location.host
      $.post ("http://+host+"/index.php/article/cpmes/ Value/1 ");
    },5000);

Extended:

Clearinterval () method
The Clearinterval () method cancels the timeout set by SetInterval ().
The parameter of the Clearinterval () method must be the ID value returned by SetInterval ().

eg

 
 

The above content is this article about the jquery Ajax technology implementation interval n seconds to a certain page to pass the value the correlation introduction, hoped everybody likes.

Related Article

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.