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