setInterval function not running on timed Interval, just repeating continuously with no time
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
精彩评论