加载datatables对象时出现问题。当我在页面加载时初始化并填充表格时,它工作正常。datatables初始化表按钮单击后(ajax,jquery)
此代码在以下页面重新开始工作完美。
<script src="https://cdn.datatables.net/1.10.10/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
var table = $('#dt_110x_complex').DataTable({
paging : true,
scrollY: 300,
ajax: "{{ url_for('complex_data') }}"
});
});
</script>
但是下面的代码在按钮单击时不起作用。我究竟做错了什么?
$(function() {
$('#proces_input').on('click', function() {
alert('Im in')
var table = $('#dt_110x_complex').DataTable({
paging : true,
scrollY: 300,
ajax: "{{ url_for('complex_data') }}"
});
});
});
按钮ID = “proces_input”。按钮点击后显示消息警报('Im in')。
下面是我的HTML表的代码(两个样本相同)的数据表:
<div class="row">
<div class="col-lg-12">
<table id="dt_110x_complex" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>id</th>
<th>code</th>
<th>date</th>
<th>blocade</th>
<th>konti</th>
<th>free</th>
<th>occ</th>
<th>origin</th>
<th>type</th>
<th>created</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
从什么我可以告诉(在尝试的jsfiddle它)它的工作(不加载原因的数据)。这里是链接:https://jsfiddle.net/aqk0egy1/1/ –
是的,JS脚本的作品,但没有数据收回。在我的Web浏览器debuger(firefox)XHR部分页面加载时,我得到一个响应(数据),但当按钮单击时,响应为空且状态码为空,传输0个字节。这不能是服务器的问题:(两个Ajax请求都是一样的) –
你没有运行它们两个都是?一个接一个? – Bindrid