我正在尝试创建一个由用户请求数据管理的注销计时器。当前的问题是,有一些Ajax调用是GET,有些是POST。在这种情况下,我希望每次用户发布文章时都扩展会话,而不是在GET上(有一些背景投票等等)。我查了查jQuery文档,看到了“bepreend”hook——听起来很不错——问题是我不知道如何使$.ajaxset成为‘POST’。有什么想法吗?谢谢。
For (much, much) better security the logout timer should be on the server side, deleting the user session x minutes after the last POST Ajax request, in your case.
You can detect the Ajax-ness of any incoming POST request by checking for the X-Requested-With: XMLHttpRequest
HTTP header.
Then, in yout javascript code, poll the server every few minutes to check if the timer has expired and a "You have been logged out" message should be displayed.