How to do the fread () function fetch data every 30 seconds without refreshing the page

0

I want the fread() or file_get_contents() function to search data in the file every 30s, but without updating the page, I tried and can not do how I can do it?

    
asked by anonymous 04.08.2017 / 04:27

1 answer

1

Use ajax, to learn more read this document from Mozilla in Portuguese

var xmlhttp = new XMLHttpRequest();
// Mude o valor da variavel url.
var url = "https://api.github.com/users?";

function get(url) {
  xmlhttp.onreadystatechange = function() {
      if (this.readyState == 4 && this.status == 200) {
          var dadosRecebidos = JSON.parse(this.responseText);
          var out = "";
          out += '<a href="' + dadosRecebidos[0].url + '">' + dadosRecebidos[0].login + '</a><br>';
          document.getElementById("resultado").innerHTML = out;
      }
  };
  xmlhttp.open("GET", url, true);
  xmlhttp.send();
  // 30000 milisegundos = 30 segundos
  setTimeout(function(){
    get(url);
  }, 30000);
}
get(url);
<div id="resultado"></div>
    
04.08.2017 / 04:36