开发者

Why does this SetInterval code work for making Ajax requests?

开发者 https://www.devze.com 2023-03-04 06:07 出处:网络
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.

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 :)

0

精彩评论

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