开发者

AJAX synchronous (SJAX) on session restore

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 cours开发者_开发问答e of action, using Ajax synchronous for a session restore.

Thank you.


There is no need to do a synchronous request here. You can cancel the form submission (return false or event.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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜