I have a following query that hits a server heartbeat every twenty seconds.
var uiBlocked = false;
window.setInterval(function() {
$.ajax({
cache: false,
type: 'HEAD',
url: '/heartbeat/',
timeout: 1000,
async: true,
success: function(data, textStatus, XMLHttpRequest) {
if (uiBlocked == true && navigator.onLine) {
uiBlocked = false;
$.unblockUI();
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
if(textStatus != 'timeout'){
if (uiBlocked == false){
uiBlocked = true;
$.blockUI({
message: "Lost connectivity, please reconnect your machine. ",
css: {
border: 'none',
padding: '15px',
backgroundColor: '#000',
'-webkit-border-radius': '10px',
'- moz-border-radius': '10px',
opacity: .5,
color: '#fff'
} });
}
}
}
})
}, 20000);
Now when the server is unavailable, I show the message
Lost connectivity, please reconnect your machine.
As a part of that message I want to also show:
Retrying in 30 (then 20 decrementing to 19, 18 and so on) seconds
Is there a way in jQuery to get hook of the interval time?