Yes, you can solve with Ajax / jQuery :
Index.php ):
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script></head><body><divid="DivSaida">
<!-- VALOR DA VARIÁVEL SERÁ MOSTRADO AQUI -->
<?php require_once("minhapagina.php"); ?>
</div>
</body>
<script type="text/javascript">
$(document).ready(function(){
minhaUrl = "minhapagina.php"; // CAMINHO DA PÁGINA COM O ECHO
setInterval(function(){
$.ajax({
url: minhaUrl,
success: function( response ) {
$('#DivSaida').html( response );
}
});
}, 5000); // TEMPO PARA ATUALIZAR EM MS (milissegundos)
});
</script>
</html>
Page with echo
of variable ( minhapagina.php):
<?php
$file = file_get_contents('json.php');
$decode = json_decode($file, true);
$ultimo = end($decode);
$variavel = $ultimo['latitude'];
echo $variavel; //MOSTRA EXATAMENTE ESSE VALOR NA PÁGINA PRINCIPAL
?>
I did not change the output of your variable , I just gave a echo
!
I left some comments in the code, which I found interesting to change.