The Jquery ajax technology is used to transmit values to a page at an interval of N seconds.

Source: Internet
Author: User

The Jquery ajax technology is used to transmit values to a page at an interval of N seconds.

Sometimes we need to pass values to a page at intervals. For example, in a chat room, it is like a database processing page that transfers values and retrieves values, and then displays them in the chat window. Or, you can check whether the last speech time of the user is two minutes from now on. If so, the user will exit. In this case, we need to use the html dom setInterval () method.

The setInterval () method can call functions or computation expressions according to the specified period (in milliseconds.

The setInterval () method does not stop calling the function until clearInterval () is called or the window is closed. The ID value returned by setInterval () can be used as a parameter of the clearInterval () method.

Syntax:

Copy codeThe Code is as follows:
SetInterval (code, millisec [, "lang"])

Code

Required. The function to be called or the code string to be executed.

Millisec

Required. The interval between periodical execution or call codes, in milliseconds.

Eg:

 setInterval(function(){      host = window.location.host      $.post("http://"+host+"/index.php/Article/cpMes/value/1");    },5000);

Extension:

ClearInterval () method
The clearInterval () method can cancel the timeout set by setInterval.
The parameter of the clearInterval () method must be the ID value returned by setInterval.

Eg:

The above content is related to the introduction of Jquery ajax technology to pass values to a page at an interval of N seconds. I hope you will like it.

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.