[英]AJAX: jQuery DataTables (Server Side) not getting any request (GET or POST) data
I'm attempting to print a simple DataTables which I want to update when I use the search/filters on any column (or the "entire table" one in the top right of the page). 我正在尝试打印一个简单的DataTables,当我在任何列(或页面右上角的“整个表格”)上使用搜索/过滤器时,我想要更新它。 When I click on a column header (to sort) the request goes through (though the page still says "processing" indefinitely).
当我点击列标题(进行排序)时,请求会通过(尽管页面仍然无限期地说“处理”)。 When I type anything into a filter it says "processing" indefinitely, but no request is passed to the server.
当我在过滤器中输入任何内容时,它会无限期地说“处理”,但没有请求传递给服务器。
Here are the scripts: 以下是脚本:
client.php client.php
<!-- jQuery and DataTables JS files, including CSS, are included here -->
<table id="employee-table" class="table-striped">
<thead>
<tr>
<th>First</th>
<th>Last</th>
<th>DOB</th>
</tr>
<tr>
<th>First</th>
<th>Last</th>
<th>DOB</th>
</tr>
</thead>
</table>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("#employee-table").dataTable({
processing: true,
serverSide: true,
ajax: {
url: "datatable.php",
type: 'POST'
}
}).columnFilter({
sPlaceHolder: "head:after",
aoColumns: [
{ type: "text" },
{ type: "text" },
{ type: "text" }
]
});
});
</script>
datatable.php datatable.php
file_put_contents("debug.txt", $_REQUEST);
echo '{
"draw": 1,
"recordsTotal": 3,
"recordsFiltered": 3,
"data": [
[
"Angelica",
"Ramos",
"1986-01-01"
],
[
"Ashton",
"Cox",
"1987-01-01"
],
[
"Test",
"Third",
"1989-01-01"
]
]
}';
As you can see, all I do on the server-side script is print all requested data to a file so I can check it. 如您所见,我在服务器端脚本上所做的就是将所有请求的数据打印到文件中,以便我可以检查它。 The problem is, no matter what I type into the filter boxes no request data goes through.
问题是,无论我在过滤器框中输入什么内容,都没有请求数据通过。 Here is a visual:
这是一个视觉:
Here is the output to the debug.txt. 这是debug.txt的输出。 NOTE that this is what is loaded into the file on the initial load of client.php, it is NOT changed when you type anything into any search boxes:
请注意,这是在client.php的初始加载时加载到文件中的内容,当您在任何搜索框中键入任何内容时,它不会更改:
Array
(
[draw] => 1
[columns] => Array
(
[0] => Array
(
[data] => 0
[name] =>
[searchable] => true
[orderable] => true
[search] => Array
(
[value] =>
[regex] => false
)
)
[1] => Array
(
[data] => 1
[name] =>
[searchable] => true
[orderable] => true
[search] => Array
(
[value] =>
[regex] => false
)
)
[2] => Array
(
[data] => 2
[name] =>
[searchable] => true
[orderable] => true
[search] => Array
(
[value] =>
[regex] => false
)
)
)
[order] => Array
(
[0] => Array
(
[column] => 0
[dir] => asc
)
)
[start] => 0
[length] => 10
[search] => Array
(
[value] =>
[regex] => false
)
)
What am I missing to get the filters to work correctly? 我错过了什么让过滤器正常工作? I assume my client-side DataTables JavaScript is misconfigured, but I can't tell how.
我假设我的客户端DataTables JavaScript配置错误,但我不知道如何。 My searches seem to be only pulling up "legacy" DataTables solutions instead of the simplified newer version they have.
我的搜索似乎只是提取“遗留”DataTables解决方案,而不是他们拥有的简化新版本。
Any help is greatly appreciated! 任何帮助是极大的赞赏!
Try as below: 请尝试以下方式:
client.php client.php
$(document).ready(function() {
var oTable = $('#employee-table').dataTable({
"bJQueryUI": true,
"bProcessing": true,
"bServerSide": true,
"bRedraw": true,
"sAjaxSource": "datatable.php",
"aoColumns": [
{"mDataProp": "first"},
{"mDataProp": "last"},
{"mDataProp": "dob"},
],
"aaSorting": [[0, "asc"]]
});
});
datatable.php datatable.php
Please check the below link and configure your database setting in the code provided by datatable. 请检查以下链接,并在datatable提供的代码中配置数据库设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.