当前存在的问题使用AJAX autorefreshes的web应用程序超时会议应用程序、存在、会议、问题

2023-09-10 16:30:03 作者:神明不知意

我正在写autorefreshes数据与设定的时间间隔AJAX调用的Web应用程序。

I'm writing a web application that autorefreshes data with an AJAX call at set intervals.

由于它做的是,服务器端的用户会话永不超时,因为最后一项活动是刷新每AJAX调用。

Because it's doing that, server side user sessions never time out, since the last activity is refreshed with every ajax call.

是否有良好的客户端的规则,我可以实现超时用户?即我应该在浏览器等追踪鼠标移动,或者我应该指出的AJAX调用到不刷新会议网址?

Are there good client side rules I could implement to time out the user? I.e. should I track mouse movements in the browser, etc., or should I point the AJAX calls to URLs that don't refresh the session?

我喜欢我的AJAX调用创下会话功能的URL,因为我也可以验证用户登录,等等。

I like that my AJAX calls hit a session-enabled URL, because I can also validate that the user is logged in, etc.

任何想法在我是否应该甚至懒得超时用户条款?

Any thoughts in terms of whether I should even bother timing out the users?

推荐答案

一种方法我用:增加之间的间隔AJAX调用每次调用时的时间。所以,你让你的第一个AJAX调用10秒后,再等待11秒时,然后13,然后16,20,25,等...(或类似的模式)。每次有活动页(通过注册一些JS事件中),重置时间回到你的初始值(如10秒)。

One technique I've used: increase the interval between AJAX calls every time a call is made. So you make your first AJAX call after 10 seconds, then you wait 11 seconds, then 13, then 16, 20, 25, etc... (or some similar pattern). Every time there's page activity (found by registering some JS event), you reset the interval back to your starting value (e.g. 10 seconds).

此方法会导致用户谁不碰的浏览器了,而超时最终,当AJAX间隔变得长于超时时间。作为额外的奖励,你会ř得出你的服务器的负载 - 如果用户离开浏览器窗口中打开很长一段时间,他们会在超时之前使越来越少的请求

This technique will cause users who don't touch the browser for a while to time out eventually, when the AJAX interval becomes longer than the timeout period. As an added bonus, you'll r educe your server loads -- if a user leaves the browser window open for a long time, they'll make fewer and fewer requests before timing out.