Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

195
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda