-1

I need function save data to refresh automatically after 5seconds,how can I do it...,

<body  onload="savedata();">

<script type="text/javascript">

 setInterval(savedata, 5000); 


 </script>
<script type="text/javascript">



function savedata() {

<script/>
Jay
  • 34,438
  • 18
  • 52
  • 81
Vincent Macharia
  • 475
  • 2
  • 7
  • 20

3 Answers3

4

You need to pass the function by reference, not the string :

<script type="text/javascript">

setInterval(savedata, 5000);

function savedata() {

}
</script>
aross
  • 5,620
  • 1
  • 25
  • 32
Hugo sama
  • 899
  • 1
  • 9
  • 19
1
var myVar = setInterval(function(){ savedata() }, 5000);

function savedata() {
}
eNVy
  • 487
  • 3
  • 10
0

Once:

<script>
setTimeout(savedata, 5000)
function savedata(){}
</script>

Every 5 secs:

<script>
function savedata(){}
let myInterval = setInterval(savedata, 5000)
//To stop
clearInterval(myInterval)
</script>
Alex Griffis
  • 708
  • 4
  • 9