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?
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?
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>