我正在JavaScript中做一個非常簡單的Comet-like long polling 下面的代碼似乎工作,但它是遞歸調用自己和吃資源?我如何看?下面的代碼是遞歸地使用內存
編輯:市價修改Dogberts建議代碼
$(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();
});
我已經運行http://home.orange.nl/jsrosman/反對它,它看起來是OK那裏(我只是在專業偏執)startAjax調用(以及callsBack)要成功哪個叫startAjax
在我原來的正式更新 - THX – Andiih