Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

192
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!