git-annex/static/longpolling.js
Joey Hess 6e40aed948 fix noscript mode to not allocate notification ids on each refresh
Now the javascript does an ajax call at the start to request the url
to use to poll, and the notification id is generated then, once we know
javascript is working.
2012-07-30 22:24:19 -04:00

25 lines
470 B
JavaScript

// Updates a div with a specified id, by polling an url,
// which should return a new div, with the same id.
connfails=0;
function longpoll(url, divid, cont, fail) {
$.ajax({
'url': url,
'dataType': 'html',
'success': function(data, status, jqxhr) {
$('#' + divid).replaceWith(data);
connfails=0;
cont();
},
'error': function(jqxhr, msg, e) {
connfails=connfails+1;
if (connfails > 3) {
fail();
}
else {
cont();
}
}
});
}