会话恢复时的 AJAX 同步 (SJAX)
我有一个大型网页(经典 ASP),其中包含用户需要的大量信息,因此需要大量输入。用户的行为是,他会随着时间的推移填写信息,在提交之前对其进行分析以及其他耗时的过程。问题是,即使会话超时设置为合理的 30 分钟,我也经常收到投诉,在提交时,用户收到超时消息并丢失了所有工作,以及他之前填写的所有内容。我认为如果会话被放弃,检查提交事件会很优雅,在这种情况下会出现登录表单。通过使用 Ajax 同步,对于会话检查以及登录本身,网页的状态将保持不变,允许用户在会话恢复后继续提交。
然而,我一直在阅读有关同步的危险以及建议如何尽可能避免的内容。对我来说,这似乎是需要同步的情况之一,但我没有找到任何人以前这样做过。 我正在寻求有关使用 Ajax 同步进行会话恢复是否是一个好的操作方案的建议。
谢谢。
I have a large web page (classic ASP) with lots of information required from the user, so lots of inputs. The user's behavior is that he will fill in the information over time, analyze it and other time consuming processes before submitting. The problem is that even though the session timeout is set to a reasonable 30 minutes, often i get complaints that when submitting, the user gets the timeout message and loses all his work, all he filled in before. I thought it would be elegant to check on the submit event if the session is abandoned, in which case to have a login form appear. By using Ajax synchronous, for the session check, and for the login itself, the state of the web page will remain unaltered, allowing the user to continue with the submit after the session has been restored.
However, I've been reading about the perils of synchronous, and how it is recommended to avoid when possible. For me it seems that this is one of those cases when synchronous is required, but i didn't find anyone that has done this before.
I am looking for advice on whether this is a good course of action, using Ajax synchronous for a session restore.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里不需要做同步请求。您可以取消表单提交(从提交处理程序中返回 false 或 event.preventDefault() ),启动异步 XMLHttpRequest 进行检查,然后在 AJAX 响应处理程序中根据需要显示一条消息或重新启动表单提交 (
form.submit()
)。如果导致这些问题,我建议 30 分钟可能不是合理的会话超时。对于用户来说,较长的超时时间和/或通过 ping 服务器的形式来保持会话活动可能是更方便的方法。
There is no need to do a synchronous request here. You can cancel the form submission (
return false
orevent.preventDefault()
from the submit handler), start the asynchronous XMLHttpRequest to do the check, then in the AJAX response handler either display a message or restart the form submission (form.submit()
) as appropriate.I'd suggest 30 minutes is probably not a reasonable session timeout if it is causing these problems. A longer timeout, and/or having the form ping the server back to keep the session alive, might be a more convenient approach for users.