The reverse ajax poll can start before the scriptSessionId is created.
This can result in 2 scriptSessions being created for a single page.
If the following happens on page load:
1. include engine.js
2. start reverse ajax polling
3. invoke a remote method which affects the script session
Here's what happens:
A script session is created for 1. but the scriptSessionId is not returned before 2. fires
scriptSessionId is null for 2. so another script session is created
3. uses the script session id from 1. since 2. has not returned yet
when 2. returns, the script session id changes
all subsequent dwr calls use the scriptSessionId returned from 2.
there are no pointers to script session 1 and it is effectively lost... therefore any initialization done in 3. is lost.
The current workaround is this:
function initReverseAjax() {
if (dwr.engine._scriptSessionId == null) {
setTimeout("initReverseAjax()", 2000);
} else {
dwr.engine.setActiveReverseAjax(true);
}
}
dwr反推技术的一个问题
最新推荐文章于 2021-02-28 03:19:35 发布
本文探讨了在创建scriptSessionId前启动逆向AJAX轮询可能导致的问题,即为单页面创建两个scriptSession的情况。详细分析了加载过程中包括引擎js文件、开始逆向AJAX轮询和调用远程方法影响scriptSession时的流程,以及由此引发的scriptSession丢失和初始化数据遗失现象。提出了通过定时器检查scriptSessionId存在的解决方案。
153

被折叠的 条评论
为什么被折叠?



