I’m doing a very simple Comet-like long polling in JavaScript
The code below seems to work, but is it recursively calling itself and eating resources? How do I tell ?
EDIT: Code edited as per Dogberts suggestion
$(document).ready(function () {
function doSuccess(data) {
$('#res').html(data.time + "<br/>" + data.data);
startAjax();
}
function doError(jqXHR, textStatus, errorThrown) {
$('#res').html(textStatus + ":" + errorThrown);
startAjax();
}
function startAjax() {
$.ajax({
url: 'http://127.0.0.1:12345/',
dataType: 'jsonp',
success: doSuccess, //Edit: updated as per Dogbert's suggestion
error: doError
});
}
startAjax();
});
I’ve run http://home.orange.nl/jsrosman/ against it and it looks to be OK there (I’m just being professionally paranoid) startAjax calls (well callsBack) to doSuccess which calls startAjax
No, this shouldn’t be eating any extra resources. You’re properly calling the method after the old request has been completed.
On a side note, this
could be written as