How to implement a periodical page refresh with a failover
I am trying improve the fault tolerance in a JSP-page that is updated on a periodical basis. A timeout is used to keep track of when it is time to submit the page.
Problem is that the communication regularly fails which leaves us with a broken/missing page that won't refresh when the communication is up and running again.
The code below is the current implementation.
function startTimer(buttonid) {
var startstring = 'myTimer("' + buttonid + '")';
window.setTimeout(startstring,15000);
}
function myTimer(buttonid) {
window.document.forms[0].submit();
}
startTimer() is called in the onload event of the page.
<body onload="startTimer('blu开发者_运维问答rp');
Best solution is a page that gracefully degrades when the communication is down. In that case it emits an error message and tries to refresh after a set period again.
I was looking at PeriodicalUpdater in Prototype as a way to solve this problem.
How about using a fake div to store the result of the ajax request, when you get a response then update the real div, when you get an error of communication than do nothing or signal to the client that the data in that div is old
new Ajax.PeriodicalUpdater($('fakeUpdateDiv'),
url, {
frequency : 30,
method : 'get',
parameters : {
},
onSuccess : function(transport) {
$('realUpdateDiv').update(transport.responseText);
},
onFailure : function(transport) {
//do something
}
});
PS: the fakeUpdateDiv
is set to display:none
精彩评论