Repeat code every 4 seconds

后端 未结 6 2120
遇见更好的自我
遇见更好的自我 2021-01-04 04:07

I want repeat this code every 4 seconds, how i can do it with javascript or jquery easly ? Thanks. :)

$.get(\"request2.php\", function(vystup){
   if (vystup         


        
6条回答
  •  情歌与酒
    2021-01-04 04:57

    It's not too hard in javascript.

    // declare your variable for the setInterval so that you can clear it later
    var myInterval; 
    
    // set your interval
    myInterval = setInterval(whichFunction,4000);
    
    whichFunction{
        // function code goes here
    }
    
    // this code clears your interval (myInterval)
    window.clearInterval(myInterval); 
    

    Hope this helps!

提交回复
热议问题