多个periodic_call_remote调用未按预期运行
我已经使用 ruby 和 Rails 很长时间了,但对于更动态的元素(目前是 jrails 和 jQuery)我还是个新手,所以我完全有可能错过了一些东西。
也就是说,我有一个页面,其中多个元素需要从多个源更新。例如,动态标头来自一个源,5-6 个 div 信息来自第二个源。我有 6-7 个 periodical_call_remote 调用,并设置了适当的 :condition 标志,因此只有可见的调用实际上会导致调用。问题是,即使其他 div 都不可见,也有 7 次调用动态标头!
为了清楚起见,我创建了一个页面来演示类似的行为:
<%= javascript_include_tag 'jquery' %>
The server time is:
<%= render :partial => 'time' %>
<%= periodically_call_remote(:update => 'time',
:url => { :action => :time },
:frequency => 3) %>.
Here's the results from some other function!
<%= render :partial => 'count' %>
<%= periodically_call_remote(:update => 'count',
:url => { :action => :count },
:frequency => 3,
:condition => "false")
%>
我期望每三秒,这将调用服务器上的“time”,并用新的 div 替换旧的“time”div。它永远不会调用“count”。
实际发生的情况是,每三秒,它就会调用“time”两次。如果我包含第三个periodic_call_remote,它会调用它三次。
这是一个错误吗?我还不明白 jQuery 的精妙之处?远古诅咒?这是怎么回事?
I've been doing ruby and rails for a long time but am a newbie when it comes to the more dynamic elements (currently jrails and jQuery), so it's entirely possible I'm missing something.
That said, I've got a page where multiple elements need updating from multiple sources. For example, a dynamic header comes from one source and 5-6 divs of information come from the second. I've got 6-7 periodically_call_remote calls with appropriate :condition flags set so only the visible one actually results in a call. The problem is, even with none of the other divs visible, there are 7 calls to the dynamic header!
For clarity, I created a page that demonstrates similar behavior:
<%= javascript_include_tag 'jquery' %>
The server time is:
<%= render :partial => 'time' %>
<%= periodically_call_remote(:update => 'time',
:url => { :action => :time },
:frequency => 3) %>.
Here's the results from some other function!
<%= render :partial => 'count' %>
<%= periodically_call_remote(:update => 'count',
:url => { :action => :count },
:frequency => 3,
:condition => "false")
%>
I'm expecting that, every three seconds, this will call 'time' on the server and replace the old 'time' div with the new one. It'll never call 'count'.
What actually happens is that, every three seconds, it calls 'time' twice. If I include a third periodically_call_remote, it'll call it three times.
Is this a bug? A subtlety of jQuery I don't yet understand? Ancient curse? What's the deal here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我显然无法结束我自己的问题,我不想删除它,以免其他人重复我的可怕错误,所以我发表评论并将其标记为答案。
答案是:升级。
I apparently can't close my own question and I don't want to delete it lest others repeat my horrifying mistake, so I'm commenting and marking that as the answer.
The answer was: Upgrade.