Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/456.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript使用Ajax页面呈现中断_Javascript_Css_Ruby On Rails_Ajax - Fatal编程技术网

Javascript使用Ajax页面呈现中断

Javascript使用Ajax页面呈现中断,javascript,css,ruby-on-rails,ajax,Javascript,Css,Ruby On Rails,Ajax,我有一个rails页面,show,有两个选项卡,项目和成员。单击其中一个选项卡时,相应的部分将通过AJAX呈现。这一切都很好,只是当我通过ajax呈现这些页面时,javascript函数似乎无法处理呈现的内容 例如,在“成员”选项卡中,我有一个链接“添加用户”,单击该链接时,某些div上的CSS display属性将从none更改为block。然而,这并不起作用。任何帮助都将不胜感激 show.html.erb application.js TurboLink可能会干扰您的代码,因为在链接上单击

我有一个rails页面,show,有两个选项卡,项目和成员。单击其中一个选项卡时,相应的部分将通过AJAX呈现。这一切都很好,只是当我通过ajax呈现这些页面时,javascript函数似乎无法处理呈现的内容

例如,在“成员”选项卡中,我有一个链接“添加用户”,单击该链接时,某些div上的CSS display属性将从none更改为block。然而,这并不起作用。任何帮助都将不胜感激

show.html.erb

application.js


TurboLink可能会干扰您的代码,因为在链接上单击它只会导致替换,而不是完全重新加载,并且ready不会触发,这会导致事件不绑定。尝试完全重新加载页面并检查它是否再次工作。嗯,是的,你肯定是对的。我担心涡轮链接可能是问题所在。除了删除ajax之外,还有什么解决方案吗?当然,它可以在:Bind to$document.onpage:load中找到,必要时也可以在更早的事件中找到。
<div id="collective_tabs">
  <%= link_to 'Projects', collective_projects_path(@collective), remote: true %>
  <%= link_to 'Members', collective_members_path(@collective), remote: true %>
</div>
<div id="collective_content">
    <%= render 'projects' %>
</div>
$('#collective_content').html("<%= escape_javascript(render 'members') %>");
<div id="collective_members">
    <div id="add_user"><%= link_to '(Add User)', '#' %></div>
    <div class="popup" id="pop_up_form">
        <div id="user_search_form">
            <%= render 'shared/user_search_form' %>
        </div>
        <div id="close_window"><%= link_to 'x', '#' %></div>
    </div>
    <div class="black_overlay" id="fade_overlay"></div>
</div>
.black_overlay {
    display: none;
}
.popup {
    display: none;
}
//= require jquery
//= require jquery.turbolinks
//= require jquery_ujs
//= require chosen-jquery
//= require messages
//= require bootstrap
//= require turbolinks
//= require_tree .

$(document).ready(function() {
    $('#add_user').click(function (event) {
      document.getElementById('pop_up_form').style.display='block'
      document.getElementById('fade_overlay').style.display='block'
      event.preventDefault(); // Prevent link from following its href
    });

    $('#close_window').click(function (event) {
      document.getElementById('pop_up_form').style.display='none'
      document.getElementById('fade_overlay').style.display='none'
      event.preventDefault(); // Prevent link from following its href
    });
});