Using jquery Ajax technology to pass values to a page every 5 seconds

Source: Internet
Author: User

Sometimes we need to pass values to a page at intervals, such as a chat room, every few seconds as the database processes the page and retrieves it, and then displays it in the chat form. Or, every once in a while to query the user's last speaking time is now 2 minutes apart. Assume that the user is exited.

At this point we're going to use the HTML DOM setinterval () method.

The SetInterval () method invokes a function or evaluates an expression according to the specified period (in milliseconds).

The SetInterval () method keeps calling functions until Clearinterval () is called or the form is closed. The ID value returned by SetInterval () can be used as a parameter for the Clearinterval () method.

Grammar:

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

Code Necessary.

The function to invoke or the code string to run.

Millisec Have to. The time interval between running periodically or calling code. Measured in milliseconds.
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 Clearinterval () method must be a parameter of the ID value returned by SetInterval ().

eg



Using jquery Ajax technology to pass values to a page every 5 seconds

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.