Why is the html() function from Ajax creating an infinite loop?

I want to output an animation while the database operation is in progress. When the db operation is finished, the contents of the table in the html document will be modified.

<script>
  var jobj = new Object();
  jobj.uid = <?php echo "'".$_SESSION['user_id']."'";?>;
  var jsoninfo = JSON.stringify(jobj); 
  var table_content = '';

  jQuery.ajax({
    type:"POST",
    url:"./get_sunda.php",
    contentType : 'application/json; charset=UTF-8',
    data : jsoninfo,
    success:function(data)
    {
      var parse_data = JSON.parse(data);
      var array_unik = parse_data.shift();
      var array_heat = parse_data.shift();
      var f_omni = parse_data.shift();
      var i = 0;
      var j = 0;      
      table_content = $('#tblReport').html();
      console.log(0);
      table_content += some_text;
      $('#tblReport').html(table_content);      
      document.getElementById('Load').style.visibility = "hidden";     
    }
  }); 

</script>

However, when I call the html () function inside an ajax code, it will fall into an infinite loop even though there is no loop.

Console output

Answers 1

  • Remove your ajax from any php/js loop, remove any setInterval function you have in the code,

    When you bind the ajax to a event you need to make sure the event isn't in a loop/setInterval/another event


Related Articles