0

I'm trying to change data in a div of HTML page every 30 seconds. Hence div must update the page data, I'm getting "too much recursion" error on js, don't know what to do, please help.

There is my code:

<script>
   // Função para inserir os dados do formulário na base de dados
   function a() {
               setTimeout( $("#mainpages").load("pages/tables/Table2.php"), 30000);
       b();
           }
           function b() {
               setTimeout($("#mainpages").load("pages/tables/Table3.php"), 30000);
       c();
           }

           function c() {
               setTimeout($("#mainpages").load("pages/tables/Table1.php"), 30000);
       a();
           }
</script>
<style>
 th { font-size: 54px; }
 td { font-size: 54px; }
 }
</style>
<body class="hold-transition skin-blue sidebar-mini" onload="a();" >

Could you help me out?

Sarvesh Mahajan
  • 914
  • 7
  • 16

1 Answers1

0

The set timeout will not sleep the code execution so your functions will be called without waiting, call the functions inside the setTimeout function

Example:

function a() {
  setTimeout(() => {
    $("#mainpages").load("pages/tables/Table2.php");
    b();
  }, 30000);
}

function b() {
  setTimeout(() => {
    $("#mainpages").load("pages/tables/Table3.php");
    c();
  }, 30000);
}

function c() {
  setTimeout(() => {
    $("#mainpages").load("pages/tables/Table1.php");
    a();
  }, 30000);
}
Diogo Peres
  • 1,302
  • 1
  • 11
  • 20