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

191
Vistas
Automatic Reload Page On Error With Javascript

I am working on an automatic refresh for when my page encounters a 500 error. I found the jquery/javascript code online here, and as it was from an older posting, and is answered, it is no longer active. I had a question about the way "check_response" is used below, as a variable, and then within the function (in 'setTimeout') set equal to the variable. I'm a little rusty on my functions, and I was wondering if 'check_response' here is used both as a variable and as a command within Python? In the OP question, Python was not one of the tags used, although I've noticed Python being related to 'check_response' after Googling it.
In short, can this script be used for non-Python appications? Thanks.

 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
   <script>
   /* Set starting and maximum retry times in seconds */
   var retry_current = 8, // first refresh at 8 seconds
       retry_max = 4096, // refresh time truncated at about 68 minutes
       check_response = function() {
       $.ajax(
           {
               url: window.location.href,
               type: "HEAD",
               complete: function (jqXHR) {
              switch (jqXHR.status) {
                  case 200:
                      window.location.reload(true);
                      break;
                  case 502:
                      if(retry_current < retry_max) {
                          retry_current *= 2;
                      }
                      setTimeout(check_response, retry_current * 1000);
              }
          }
      });
  };
setTimeout(check_response, retry_current * 1000);
</script>

Below is the Javascript code for the page's main function: the loading of news items upon page refresh:

<script>
var reloadUrl = {{reloadUrl|json_encode|raw}};
window.setTimeout(function () {
window.location = reloadUrl;
}, 5000); //5 seconds
</script>
about 4 years ago · Juan Pablo Isaza
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