Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

238
Vistas
JavaScript code to read the latest values from a json file that keeps getting updated every few seconds

I am very new to JavaScript and trying to display the latest values from a .json file, that keeps getting updated every 10 seconds, into a HTML page. I am reading the file every 10 seconds as well, but I am not getting the latest values from the file. I am getting values which are 50 to 60 seconds older.

I have tried disabling the browser cahche in chrome but still the same issue. Can somebody please help on this?

My JavaScript code to read the json file is as follows:

function readJsonFile(callback) {
 var request = new XMLHttpRequest();
 request.open('GET', 'http://localhost:8080/PersonalProject/filename.json');
 request.onload = function() {
  if(request.status>=100 && request.status<=100) {
   //perform some operation
   callback(request.responseText);
  }
  else{
   //perform some operation
   callback('FAILED');
  }
 };
 request.onerror = function() {
  console.error('Connection error');
 };
 request.send();
}


setInterval(function(){
 readJsonFile(function(stat){
  console.log(stat);
 });
}, 10000);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can add a timestamp as a parameter in your request to avoid the navigator cache:

...
let ms = Date.now();
request.open('GET', 'http://localhost:8080/PersonalProject/filename.json?ms' + ms);
...

I do that any time i need to update js and css files when requested from the html header and it works

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda