我寫了很長時間的輪詢助手類,因爲$ .getJSON方法我異步它不會遞歸,不會溢出正確嗎? (遞歸作爲responseCallback調用startPolling可以使用「遞歸」回調堆棧溢出嗎?
MyApp.Polling = function (url, parameters, callback) {
this.url = url;
this.parameters = parameters;
this.callback = callback;
this.startPolling();
};
MyApp.Polling.prototype = {
abort: function() {
if (this.request != null) {
this.request.abort();
}
},
startPolling: function (xhr) {
if (xhr != null && xhr.status == 0) return;
this.request = $.getJSON(this.url, this.parameters, $.proxy(this.responseCallback, this));
this.request.error($.proxy(this.startPolling, this));
},
responseCallback: function (data) {
this.callback(data);
this.startPolling();
}
};
編輯:謝謝你的快速反應,大家好,我有一個問題在Firebug有很多看起來像他們仍然在等待響應(小微調器旁邊紡紗請求請求)但是它們應該被提供(正如你在代碼中看到的,一次只提供一個請求),如果我關閉了整個web服務器,它們不會被中止,它們會繼續旋轉,是螢火蟲錯誤還是我我的長時間輪詢有問題嗎?謝謝