有关,当我点击一个按钮,我的控制器所得jQuery函数某些原因被调用两次。由于js函数被调用的切换,这是一个问题,因为它会导致code跳入水中拿出来看。
For some reason when I click on a button, my controller and the resulting jquery function gets called twice. Since the js function being called is toggle, this is a problem as it causes the code to jump in and out of view.
下面的形式:
Unseen Notifications: <%= current_user.notification_unseen %> </div>
<%= button_to "show", {:action => "seen", :controller=>"notifications"}, :remote => true %>
下面是控制器:
def seen
respond_to do |format|
format.js
end
end
下面是jQuery的:
Here is the jquery:
$("div#notifications").toggle();
$("div#count").html("<%= escape_javascript( render :partial => 'notifications/count')%>");
我在为什么在地球上,这将可能发生的损失。我一直很小心,不要双击,不知道如何prevent它。任何建议,将不胜AP preicated。
I am at a loss for why on earth this would possibly happen. I have been very careful not to double click and don't know how to prevent it. Any suggestions would be greatly appreicated.
我最近类似这样的问题之前,我有2个的jQuery库包括在内。特别是要检查您只有jquery_ujs.js而不是的jquery.js。看来,当你包括他们的某些JS函数调用两次一样。
I had a recent problem like this before, when I had 2 jquery libraries included. In particular, check that you only have jquery_ujs.js and not jquery.js. Seems like when you include both of them certain js functions are called twice.
希望这有助于!