开发者

setInterval function not running on timed Interval, just repeating continuously with no time

开发者 https://www.devze.com 2023-03-05 00:30 出处:网络
Just curious, I have this function: setInterval( function(){ sendAjax(\'search\', eInput, function(responseText){

Just curious, I have this function:

setInterval( function(){
       sendAjax('search', eInput, function(responseText){
              $("#txtResp").html(responseText);
       })
}, 5000 );

It runs this function continuously, with no interval. It causes my sendAjax function to run like crazy.

I just need it to run every 5 seconds. Any help?

Regards,

Taylor开发者_开发知识库


Doubt this is the problem, but don't forget to end your lines with a semicolon

setInterval( function(){
         sendAjax('search', eInput, function(responseText){
                $("#txtResp").html(responseText);
         }); // <---
 }, 5000 );

Also it could be a problem that just because you're doing something every 5 seconds, the callback to sendAjax will be executed when a response is received regardless of the interval. So you may be seeing consecutive responses repeatedly writing to the #txtResp div

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号