相关疑难解决方法(0)

Rails:由于某些原因,JS控制器被称为两次

出于某种原因,当我点击一个按钮时,我的控制器和生成的jquery函数被调用两次.由于调用的js函数是切换,这是一个问题,因为它会导致代码跳入和跳出视图.

这是表格:

Unseen Notifications: <%=  current_user.notification_unseen %> </div>
                <%= button_to "show", {:action => "seen", :controller=>"notifications"}, :remote => true %>
Run Code Online (Sandbox Code Playgroud)

这是控制器:

def seen
    respond_to do |format|
      format.js 
    end
  end
Run Code Online (Sandbox Code Playgroud)

这是jquery:

$("div#notifications").toggle();
$("div#count").html("<%= escape_javascript( render :partial => 'notifications/count')%>");
Run Code Online (Sandbox Code Playgroud)

我不知道为什么地球上可能会发生这种情况.我一直非常小心,不要双击,不知道如何防止它.任何建议都会有很大的意义.

javascript ruby ajax jquery ruby-on-rails

6
推荐指数
2
解决办法
3281
查看次数

标签 统计

ajax ×1

javascript ×1

jquery ×1

ruby ×1

ruby-on-rails ×1