Javascript 如何使用jquery ajax重新加载数据表
这是我的桌子Javascript 如何使用jquery ajax重新加载数据表,javascript,jquery,ruby-on-rails-4,Javascript,Jquery,Ruby On Rails 4,这是我的桌子 <table class="table table-hover display search dataTable" id="test" cellspacing="0" > <thead> <tr> <th> ID </th> <th>Name</th> <th>Age</th> <th>Email
<table class="table table-hover display search dataTable" id="test" cellspacing="0" >
<thead>
<tr>
<th> ID </th>
<th>Name</th>
<th>Age</th>
<th>Email</th>
</tr>
</thead>
<tbody >
<% all_employees.each do |employee|%>
<tr>
<td> <%= check_box_tag 'employee_ids[]', employee.id %> </td>
<td> <%= employee.name %> </td>
<td> <%= employee.age %> </td>
<td> <%= employee.email %> </td>
</tr>
<% end %>
</tbody>
</table>
我在rails 4版本中使用RubyonRails
单击一个按钮,我调用这个ajax请求,我得到了预期的响应,但是当在ajax中触发成功时,我得到了一个新表,它覆盖了旧表。如何解决这个问题
提前感谢我建议将您的
放在其他容器中,并在ajax success上刷新该容器,如下所示:
<div class="tableWrapper">
<table class="table table-hover display search dataTable" id="test" cellspacing="0" >
....
</table>
</div>
我也尝试过这样做,它在旧页面上绘制整个页面(在成功的ajax调用中),在我的查询中,它只绘制您从
/associated\u employees
返回的表?在浏览器的开发者控制台或firebug中,您可以检查返回的内容吗?我的意思是,它是用
标记返回整个页面,还是简单地用
标记响应整个页面?整个页面都指向view:same view show.html,其中我将此表呈现为一个部分,这样做也正确吗?我认为/associated_employees
应该只返回带有
作为起始标记和
作为结束标记的视图
<div class="tableWrapper">
<table class="table table-hover display search dataTable" id="test" cellspacing="0" >
....
</table>
</div>
function filtered_employee(group_id){
$.ajax({
url: "/employee_groups/"+group_id+"/associated_employees",
type: "get",
data: {
"id" : group_id
},
success: function(result) {
$('.tableWrapper').html(result)
},
error: function(result){
$('.tableWrapper').html(result.responseText)
}
});
}