Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.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
Jquery 如何刷新表行直到数据库状态?_Jquery_Ruby On Rails_Ajax - Fatal编程技术网

Jquery 如何刷新表行直到数据库状态?

Jquery 如何刷新表行直到数据库状态?,jquery,ruby-on-rails,ajax,Jquery,Ruby On Rails,Ajax,我有一个表,它通过ajax为新行添加了前缀 \u group.html.erb <%= content_tag_for(:tr, @group, class: 'group-new-row') do %> <td><%= group.title %></td> <td><%= group.owner_id %></td> <td> <%= link_to 'e

我有一个表,它通过ajax为新行添加了前缀

\u group.html.erb

<%= content_tag_for(:tr, @group, class: 'group-new-row') do %>
    <td><%= group.title %></td>
    <td><%= group.owner_id %></td>
    <td>
      <%= link_to 'edit', edit_group_path(:id => group.id), class: "btn btn-primary btn-xs" %>
      <%= link_to 'delete', group, remote: true, method: :delete,  data: { confirm: 'sure?' },
                  class: "btn btn-danger btn-xs" %>
    </td>
<% end %>
$("#grouptable").prepend('<%= j render(@group)%>');
<table class="table table-striped">
  <thead>
  <tr>
    <th>title</th>
    <th>ID</th>
    <th></th>
  </tr>
  </thead>

  <tbody id="grouptable">

  <%= content_tag_for(:tr, @groups) do |group| %>
      <td><%= group.title %></td>
      <td><%= group.owner_id %></td>
      <td>
        <%= link_to 'edit', edit_group_path(:id => group.id), class: "btn btn-primary btn-xs" %>
        <%= link_to 'delete', group, remote: true, method: :delete,  data: { confirm: 'sure?' },
                    class: "btn btn-danger btn-xs" %>
      </td>

  <% end %>

  </tbody>

</table>
在你的js中

var newFollow = true;
var getNewRow = function(){
 if(newFollow){
    $.ajax({
       // ur call here 
    })
  }else{
    clearInterval(interval);
  }
}
var interval = setInterval("getNewRow",5000);
在您的create.js.erb中

$("#grouptable").prepend('<%= j render(@group)%>');
newFollow = // model.new_follow, this should be true or false;
$(“#grouptable”).prepend(“”);
newFollow=//model.new\u follow,这应该是true或false;
我希望这有帮助。

在你的js中

var newFollow = true;
var getNewRow = function(){
 if(newFollow){
    $.ajax({
       // ur call here 
    })
  }else{
    clearInterval(interval);
  }
}
var interval = setInterval("getNewRow",5000);
在您的create.js.erb中

$("#grouptable").prepend('<%= j render(@group)%>');
newFollow = // model.new_follow, this should be true or false;
$(“#grouptable”).prepend(“”);
newFollow=//model.new\u follow,这应该是true或false;

我希望这能有所帮助。

你能解释得更清楚些吗?新的后续是在你的js或ruby方面吗?@HarryBomrah我试过这么做。请看问题的最后一部分:new_follow是db records的字段,所以我想你会问,一旦new_follow设置为false,你想停止定期刷新你的js。我说得对吗?你能解释得更清楚些吗?新的跟随是在你的js或ruby方面吗?@HarryBomrah我试过这么做。请看问题的最后一部分:new_follow是db records的字段,所以我想你会问,一旦new_follow设置为false,你想停止定期刷新你的js。我说得对吗?