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>