如何使用服务器端处理(PHP)填充jquery数据表?

如何使用服务器端处理(PHP)填充jquery数据表?,php,datatable,datatables,server-side-scripting,Php,Datatable,Datatables,Server Side Scripting,我试图用服务器端的PHP脚本填充一个datatable,该脚本从postgres表~75K行回显数据。我按照中给出的步骤实现了它,但表中没有显示任何数据。这就是我长久以来所拥有的: jsp文件中的表定义: <table id="myTable" class="table table-striped" width="100%"> <thead> <t

我试图用服务器端的PHP脚本填充一个datatable,该脚本从postgres表~75K行回显数据。我按照中给出的步骤实现了它,但表中没有显示任何数据。这就是我长久以来所拥有的:

jsp文件中的表定义:

<table id="myTable" class="table table-striped" width="100%">
                            <thead>
                                <tr>
                                    <th>idpersona</th>
                                    <th>primerapellido</th>
                                    <th>primernombre</th>
                                    <th>numeroidentificacion</th>
                                    <th>fechanacimiento</th>
                                </tr>
                            </thead>
                            <tfoot>
                                <tr>
                                    <th>idpersona</th>
                                    <th>primerapellido</th>
                                    <th>primernombre</th>
                                    <th>numeroidentificacion</th>
                                    <th>fechanacimiento</th>
                                </tr>
                            </tfoot>
                        </table>
以下是Firebug在我访问包含以下表格的应用程序页面时显示的信息:

_   1440905636814
columns[0][data]    0
columns[0][name]    
columns[0][orderable]   true
columns[0][search][regex]   false
columns[0][search][value]   
columns[0][searchable]  true
columns[1][data]    1
columns[1][name]    
columns[1][orderable]   true
columns[1][search][regex]   false
columns[1][search][value]   
columns[1][searchable]  true
columns[2][data]    2
columns[2][name]    
columns[2][orderable]   true
columns[2][search][regex]   false
columns[2][search][value]   
columns[2][searchable]  true
columns[3][data]    3
columns[3][name]    
columns[3][orderable]   true
columns[3][search][regex]   false
columns[3][search][value]   
columns[3][searchable]  true
columns[4][data]    4
columns[4][name]    
columns[4][orderable]   true
columns[4][search][regex]   false
columns[4][search][value]   
columns[4][searchable]  true
draw    1
length  20
order[0][column]    0
order[0][dir]   asc
search[regex]   false
search[value]   
start   0
提前谢谢

解决方案

正确的选项名称是bProcessing和bServerSide。DataTables初始化代码应为:

$('#myTable').dataTable({
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "/tablabd.php"
});
注释


我已经将URL更改为/tablabd.php,因为如果您的HTML和php位于不同的域上,Ajax调用可能会失败,除非您允许跨域请求。确保在同一个域上有HTML和PHP。

好的。问题是我的apache服务器没有启动是的,我很笨,CORS请求是不允许的。如果我在你之前就发布了这篇文章,我就可以省下5天的痛苦了。附言:在看你的答案之前,我自己解决了这个问题,但无论如何它是正确的。谢谢。你知道我可以在Spring项目的哪个文件夹中包含PHP脚本以避免使用CORS请求吗?我已经尝试了我能找到的所有资源文件夹。@traba_jin,我不熟悉Spring项目,但我认为您可以将PHP脚本放在任何文件夹中,或者为您的脚本创建一个新文件夹。
{"sEcho":0,"iTotalRecords":74047,"iTotalDisplayRecords":74047,"aaData":[["e71657b3-a7f5-4a10-bc43-d0edbeb5cdab","PEREZ","ABDON","4299249","1947-07-10 00:00:00"],["796db2d4-fee3-4cca-ae06-429a2ea6c5af","TORREZ","MARIA","24240762","1951-09-17 00:00:00"]]}
_   1440905636814
columns[0][data]    0
columns[0][name]    
columns[0][orderable]   true
columns[0][search][regex]   false
columns[0][search][value]   
columns[0][searchable]  true
columns[1][data]    1
columns[1][name]    
columns[1][orderable]   true
columns[1][search][regex]   false
columns[1][search][value]   
columns[1][searchable]  true
columns[2][data]    2
columns[2][name]    
columns[2][orderable]   true
columns[2][search][regex]   false
columns[2][search][value]   
columns[2][searchable]  true
columns[3][data]    3
columns[3][name]    
columns[3][orderable]   true
columns[3][search][regex]   false
columns[3][search][value]   
columns[3][searchable]  true
columns[4][data]    4
columns[4][name]    
columns[4][orderable]   true
columns[4][search][regex]   false
columns[4][search][value]   
columns[4][searchable]  true
draw    1
length  20
order[0][column]    0
order[0][dir]   asc
search[regex]   false
search[value]   
start   0
$('#myTable').dataTable({
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "/tablabd.php"
});