git-annex/static/longpolling.js

26 lines
470 B
JavaScript
Raw Normal View History

// Updates a div with a specified id, by polling an url,
// which should return a new div, with the same id.
connfails=0;
2012-07-31 00:33:23 +00:00
function longpoll(url, divid, cont, fail) {
2012-07-31 00:22:10 +00:00
$.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) {
2012-07-31 00:33:23 +00:00
fail();
}
2012-07-31 00:22:10 +00:00
else {
cont();
}
}
});
}