Rails 3:jquery.idletimeout 插件的远程请求失败
我在 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”。不确定这是否是问题的一部分......
无论如何,这很长,但是有人看到问题是什么吗?谢谢。
I'm using the jquery.idletimeout plugin with the following in my application.js:
jQuery.idleTimeout('#session_timeout', '#session_timeout a', {
idleAfter: 600,
pollingInterval: 15,
keepAliveURL: '/session',
serverResponseEquals: 'OK',
// Additional "on" event functions...
});
Here is some relevant Ruby code:
# /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"
However, when a page is loaded, my browser's (Chrome) Network console is showing the following (and Firefox's shows an "Aborted" status):
Requests from the plugin to '/session' are made, but something is messing up. The plugin is seeing these 5 responses as failed and is therefore aborting. To test, I created the following remote link to the same controller/action:
<%= link_to 'test remote session', session_path, :remote => true %>
If I click this everything seems to work fine. (Last request in screenshot above.) I noticed in my development.log file a difference between the plugin's request and the remote link's request:
# 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)
The remote link request shows "...#show as JS" while the plugin's doesn't include the "JS". Not sure if this is part of the problem...
Anyway, this is long, but does anyone see what the issue is? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有同样的问题。 idleTimeout支持AJAXTimeout选项,默认为250ms,但显然它太慢了(或者默认值实际上不起作用)。无论哪种情况,如果您只是将其增加到 500 或稍大一些的数字,它就可以正常工作。
I had the same exact problem. idleTimeout supports an AJAXTimeout option, which defaults to 250ms, but apparently it's too slow (or the default doesn't actually work). In either case, if you just increase that to 500 or some slightly larger number, it works fine.