I have this code:
setInterval(sendAjax('search', 'q'), 100 * 1开发者_如何转开发0);
Which I thought would work to execute my function sendAjax(param,param) every 1 second.
However, this is not the case. It only executed the function once.
Does anyone know why this occurs and any solutions?
Regards, Taylor
I think you have to do the following:
setInterval("sendAjax('search', 'q')", 100 * 10);
It doesn't look like you're using setInterval() right.
Usually it is used like:
setInterval("aFunction()", 100 * 10);
The reason why your script is invoking once is because the interpreter evaluates sendAjax('search', 'q') once. This is the only invocation that it makes.
Check out this link under setInterval():
http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/
Hope it helps :)
精彩评论