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.