summaryrefslogtreecommitdiff
path: root/static/longpolling.js
blob: 965c1d18dbab13be5090208ecec0281681eff531 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// 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();
			}
		}
	});
}