我尝试实施长时间的轮询聊天。我的聊天正常运行,除了一个浏览器-野生动物园。 通过此代码,我会收到新消息(此处仅一部分,仅用于理解递归):
let errorCounter = 0;
let getchatText = function () {
let options = {
//headers and other configuration,which needed for XMLHttpRequest
};
let responseHandler = function(responseCode,body) {
switch (responseCode) {
//handle response codes
case 200:
errorCounter = 0; //on success response
// other codes handle here
default:
errorCounter++;
}
if (errorCounter >= 30) { // 30 just for testing
endChatSession(true);
} else {
getchatText(); //recursion
}
};
requestCall(options,false,responseHandler);
};
如果过一会儿我重新加载页面-它没有停止,但是tryis调用了很多次(在我的情况下为30次),并且endChatSession
出现了太多错误。但是在其他浏览器(chrome,firefox等)中-它立即停止递归并重新加载页面。
这是控制台输出,在重新加载safari页面之前(保留日志):
Question
:如何在Safari中重新加载页面时停止递归,因为这不是endChatSession