Hi,
I use ajax call for update the gui in a web project. When the device go out of the network, works the gui wrong.
So I implmented a ajax function, that check the connection and when the device is offline, the GUI will blocked.
To do that, I use: jquery.js and jquery.blockUI.js
var launchfilleIntervall;
var isBlocked = false;
function isServerLost() {
jQuery.ajax({
type: "POST",
url: "ServerLostServlet",
dataType:"xml",
data:"",
timeout: 250,
success:function(response){
if (isBlocked) {
$.unblockUI();
}
isBlocked = false;
// do something
},
error:function (xhr, ajaxOptions, thrownError){
if (!isBlocked) {
$.blockUI();
}
isBlocked = true;
}
});
}
function stopAjax() {
if (launchfilleIntervall) {
window.clearInterval(launchfilleIntervall);
}
}
function startAjax() {
if (!launchfilleIntervall) {
launchfilleIntervall = window.setInterval('isServerLost()', 1500);
}
}
I change the HTML source and add to the body tag:
onload="startAjax()"
onunload="stopAjax()"