简体   繁体   English

AJAX:jQuery DataTables(服务器端)没有获得任何请求(GET或POST)数据

[英]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: 这是一个视觉:

请注意,在屏幕右上角搜索198,持续“Processing ...”

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提供的代码中配置数据库设置。

Server Side Code 服务器端代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jQuery Datatables Server侧面分页自定义HTTP POST请求和响应 - jQuery Datatables Server side pagination with custom HTTP POST request and response Ajax请求数据表中每个页面的服务器端数据 - Ajax request for server side data for each page in Datatables jQuery ajax发布请求的MVC服务器端验证 - mvc server-side validation for jquery ajax post request jQuery Ajax POST 请求获取数据 - jQuery Ajax POST request get data AJAX请求php以获取由post / get发送的指定目录中服务器上文件的列表(WITHOUT JQUERY) - AJAX request to php for getting the list of the file on the server in the specified directory sent by post/get (WITHOUT JQUERY) Ajax同步发布方法,从节点服务器端获取数据 - Ajax synchronous post method, get data from Node server side 如何访问 ajax.data object 进行服务器端处理(jquery DataTables)? - How to access the ajax.data object for server-side processing (jquery DataTables)? 数据表服务器端ajax和sAjaxSource具有不同的请求参数 - Datatables server side ajax and sAjaxSource have different request parameter ajax-jquery发布,服务器不接收任何表单数据 - ajax-jquery post, server ist not receiving any form data 如何在没有 Ajax 的情况下在 JQuery DataTables 中使用服务器端处理 - How to use server-side processing in JQuery DataTables without Ajax
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM