setInterval() behaviour with 0 milliseconds in JavaScript

前端 未结 4 983
孤独总比滥情好
孤独总比滥情好 2020-11-27 21:18

In my application I found some JavaScript code that is using setInterval with 0 milliseconds, like so:

self.setInterval(\"myFunction()\",0);
         


        
4条回答
  •  孤街浪徒
    2020-11-27 21:45

    To have it executed only once with minor delay, use setTimeOut instead:

    window.setTimeout(myFunction, 10);
    

    As you're using AJAX, you don't have to use any timers at all - just call the next AJAX request in the Callback (complete/success event) of the current AJAX request.

    Post your current code and we might be able to guide you further.

提交回复
热议问题