0

我在 application.js 中使用了 jquery.idletimeout 插件,其中包含以下内容:

jQuery.idleTimeout('#session_timeout', '#session_timeout a', {
  idleAfter: 600,
  pollingInterval: 15,
  keepAliveURL: '/session',
  serverResponseEquals: 'OK',
  // Additional "on" event functions...
});

以下是一些相关的 Ruby 代码:

# /app/controllers/sessions_controller.rb
class SessionsController < ApplicationController
  respond_to :html, :only => [:new, :create, :destroy]
  respond_to :js, :only => [:show]

  # Used by the jQuery.idleTimeout plugin
  def show
    if current_user_account # method to check for logged in user
      render :text => 'OK'
    else
      render :text => 'NOT OK', :status => 404
    end
  end
end

# /config/routes.rb
resource :session
resources :sessions
get 'login' => "sessions#new", :as => "login"  
get 'logout' => "sessions#destroy", :as => "logout"

但是,当加载页面时,我的浏览器 (Chrome) 网络控制台显示以下内容(并且 Firefox 显示“已中止”状态):

截屏

插件向“/session”发出了请求,但有些事情搞砸了。该插件将这 5 个响应视为失败,因此正在中止。为了测试,我创建了以下指向同一控制器/操作的远程链接:

<%= link_to 'test remote session', session_path, :remote => true %>

如果我点击这个,一切似乎都很好。(上面屏幕截图中的最后一个请求。)我在 development.log 文件中注意到插件请求和远程链接请求之间存在差异:

# Request from plugin:
Started GET "/session" for 127.0.0.1 at 2011-06-16 13:31:33 -0400
Processing by SessionsController#show as 
...
Rendered text template (0.0ms)
Completed 200 OK in 898ms (Views: 1.0ms | ActiveRecord: 21.8ms | Sphinx: 0.0ms)

# Request from remote link:
Started GET "/session" for 127.0.0.1 at 2011-06-16 13:33:36 -0400
Processing by SessionsController#show as JS
...
Rendered text template (0.0ms)
Completed 200 OK in 918ms (Views: 1.0ms | ActiveRecord: 2.5ms | Sphinx: 0.0ms)

远程链接请求显示“...#show as JS ”,而插件不包含“JS”。不确定这是否是问题的一部分...

无论如何,这很长,但是有人知道问题是什么吗?谢谢你。

4

1 回答 1

1

我有同样的问题。idleTimeout 支持 AJAXTimeout 选项,默认为 250 毫秒,但显然它太慢了(或者默认值实际上不起作用)。无论哪种情况,如果您只是将其增加到 500 或稍大的数字,它就可以正常工作。

于 2011-11-12T00:25:27.277 回答