Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
数据表jquery+;ajax+;php可以';t获取表中的数据(服务器端处理)_Php_Jquery_Ajax_Datatables_Serverside Javascript - Fatal编程技术网

数据表jquery+;ajax+;php可以';t获取表中的数据(服务器端处理)

数据表jquery+;ajax+;php可以';t获取表中的数据(服务器端处理),php,jquery,ajax,datatables,serverside-javascript,Php,Jquery,Ajax,Datatables,Serverside Javascript,我在下面的示例中使用datatable 所以我的桌子是: <table cellpadding="0" cellspacing="0" border="0" class="display" id="tabellaGlossario"> <thead> <th> <td>Voce</td> <td>Sinonimi</td>

我在下面的示例中使用datatable

所以我的桌子是:

<table cellpadding="0" cellspacing="0" border="0" class="display" id="tabellaGlossario">
    <thead>
        <th>
             <td>Voce</td>
             <td>Sinonimi</td>
             <td>Sigla</td>
             <td>Macrosettore</td>
             <td>Microsettore</td>      
             <td>Sinonimi</td>
             <td>Sigla</td>
             <td>Macrosettore</td>
             <td>Microsettore</td>           
        </th>
    </thead>
    <tfoot>
        <th>
             <td>Voce</td>
             <td>Sinonimi</td>
             <td>Sigla</td>
             <td>Macrosettore</td>
             <td>Microsettore</td>      
             <td>Sinonimi</td>
             <td>Sigla</td>
             <td>Macrosettore</td>
             <td>Microsettore</td>           
        </th>
    </tfoot>
</table>
我的问题是,我总是得到“表中没有可用数据”作为表结果。但是正如您所看到的,ajax有一些结果(本例中为1)。 我的代码似乎与官方示例中的代码相同


无法理解为什么数据不显示在表中(并且我在浏览器控制台中没有得到错误)

您使用的是动态加载还是任何类型的路由? 例如angularjs ngroute或某些框架

在这种情况下,它不能工作(不像你正在做的那样)。您可以按照以下指南或示例进行操作
http://jsfiddle.net/qu4a7j24/3/

<div ng-app='testTableApp'>

    <div class="container">
        <div ng-controller="mainTable">
            <form action="" method="POST" class="form-horizontal" role="form">
                <div class="form-group">
                    <legend>Filters</legend>
                </div>
                <div class="form-group">
                    <div class="col-sm-10 col-sm-offset-2">
                        <input type="text" value="0" ng-change='reloadData()' ng-model="start">
                        <input type="text" value="50" ng-change='reloadData()' ng-model="end">

                    </div>
                </div>
            </form>

            <table datatable="" dt-options="dtOptions" dt-columns="dtColumns" class="table table-striped table-bordered"></table>
        </div>
    </div>
</div>

var testTableApp = angular.module( 'testTableApp', ['ngRoute', 'ngResource', 'datatables', 'datatables.tabletools', 'datatables.bootstrap', 'datatables.fixedheader'] );
console.log( testTableApp );
testTableApp.controller("mainTable", 
[ '$scope', 'DTOptionsBuilder', 'DTColumnBuilder',
    function ( $scope, DTOptionsBuilder, DTColumnBuilder){
        $scope.dataSource = "http://dt.ishraf.com/ajax.php";
        $scope.start = 0;
        $scope.end = 5000;


        $scope.getDataSource = function(obj,prefix){
            var src = $scope.dataSource;

            var str = [];
            for(var p in obj) {
                if (obj.hasOwnProperty(p)) {
                    var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p];
                    str.push(typeof v == "object" ?
                    serialize(v, k) :
                    encodeURIComponent(k) + "=" + encodeURIComponent(v));
                }
            }
            return src + "?" + str.join("&");
        }

        var dsParams = {
            start : $scope.start,
            end : $scope.end
        }

        $scope.dsString = $scope.getDataSource( dsParams );


        $scope.buildTable = function(){
            return DTOptionsBuilder
                .newOptions()
                .withOption('ajax', {
                    // Either you specify the AjaxDataProp here
                    dataSrc: 'data',
                    url: $scope.dsString,
                    type: 'POST'
                }).
                withOption( 'lengthMenu', [
                    [10, 20, 50, 100, 150, 300, 500],
                    [10, 20, 50, 100, 150, 300, 500]
                ])                
                .withTableTools('bower_components/datatables-tabletools/swf/copy_csv_xls_pdf.swf')
                .withTableToolsButtons([
                    {
                        "sExtends": "copy",
                        "sButtonText": "<i class='fa fa-copy'></i>&nbsp;|&nbsp;Copy",
                        "fnInit": function (nButton, oConfig) {
                            $(nButton).addClass('btn btn-success');
                        }
                    },
                    {
                        "sExtends": "print",
                        "sButtonText": "<i class='fa fa-print'></i>&nbsp;|&nbsp;Print",
                        "fnInit": function (nButton, oConfig) {
                            $(nButton).addClass('btn btn-danger');
                        }
                    },
                    {
                        "sExtends": "csv",
                        "sButtonText": "<i class='fa fa-file-o'></i>&nbsp;|&nbsp;CSV",
                        "fnInit": function (nButton, oConfig) {
                            $(nButton).addClass('btn btn-primary');
                        }
                    },
                    {
                        "sExtends": "pdf",
                        "sButtonText": "<i class='fa fa-file-pdf-o'></i>&nbsp;|&nbsp;PDF",
                        "fnInit": function (nButton, oConfig) {
                            $(nButton).addClass('btn btn-warning');
                        }
                    }
                ])
                .withFixedHeader({
                    bottom: true
                })
                .withDOM('<"clear"><"#top.hidden-print"<".row"<".col-md-6"i><".col-md-6"f>><".row"<".col-md-6"l><".col-md-6"p>><"clear">T>rt')
                ;            
        }


        $scope.dtOptions = $scope.buildTable();

        $scope.buildColumns = function(){
            return [
                DTColumnBuilder.newColumn('id').withTitle('ID'),
                DTColumnBuilder.newColumn('firstName').withTitle('First name'),
                DTColumnBuilder.newColumn('lastName').withTitle('Last name'),
                DTColumnBuilder.newColumn('city').withTitle('city'),
                DTColumnBuilder.newColumn('state').withTitle('state'),
                DTColumnBuilder.newColumn('zip').withTitle('zip'),
                DTColumnBuilder.newColumn('country').withTitle('country'),
                DTColumnBuilder.newColumn('phone').withTitle('phone'),
                DTColumnBuilder.newColumn('email').withTitle('email')
            ];
        }

        $scope.dtColumns = $scope.buildColumns();


        $scope.reloadData = reloadData;
        $scope.dtInstance = {};

        function reloadData() {
            var resetPaging = false;
            $scope.dtInstance.reloadData(callback, resetPaging);
        }

        function callback(json) {
            console.log(json);
        }

    }
]);

过滤器
var testTableApp=angular.module('testTableApp',['ngRoute','ngResource','datatables','datatables.tabletools','datatables.bootstrap','datatables.fixedheader']);
log(testTableApp);
testTableApp.controller(“mainTable”,
['$scope'、'DTOptionsBuilder'、'DTColumnBuilder',
函数($scope、DTOptionsBuilder、DTColumnBuilder){
$scope.dataSource=”http://dt.ishraf.com/ajax.php";
$scope.start=0;
$scope.end=5000;
$scope.getDataSource=函数(obj,前缀){
var src=$scope.dataSource;
var-str=[];
用于(obj中的var p){
if(对象hasOwnProperty(p)){
变量k=前缀?前缀+“[”+p+“]”:p,v=obj[p];
str.push(typeof v==“object”?
序列化(v,k):
encodeURIComponent(k)+“=”+encodeURIComponent(v));
}
}
返回src+“?”+str.join(“&”);
}
var dsParams={
开始:$scope.start,
end:$scope.end
}
$scope.dsString=$scope.getDataSource(dsParams);
$scope.buildTable=函数(){
返回DTOptionsBuilder
.newOptions()
.withOption('ajax'{
//您可以在此处指定AjaxDataProp
dataSrc:'数据',
url:$scope.dsString,
类型:“POST”
}).
withOption('lengthMenu'[
[10, 20, 50, 100, 150, 300, 500],
[10, 20, 50, 100, 150, 300, 500]
])                
.withTableTools('bower_components/datatables tabletools/swf/copy_csv_xls_pdf.swf'))
.使用TableTools按钮([
{
“复制”,
“sButtonText”:“复制”,
“fnInit”:函数(nButton、oConfig){
$(nButton).addClass('btn btn success');
}
},
{
“性倾向”:“打印”,
“sButtonText”:“打印”,
“fnInit”:函数(nButton、oConfig){
$(n按钮).addClass('btn btn danger');
}
},
{
“性倾向”:“csv”,
“sButtonText”:“CSV”,
“fnInit”:函数(nButton、oConfig){
$(nButton).addClass('btn btn primary');
}
},
{
“性倾向”:“pdf”,
“sButtonText”:“| PDF”,
“fnInit”:函数(nButton、oConfig){
$(nButton).addClass('btn btn warning');
}
}
])
.带固定标题({
底部:正确
})
.withDOM('rt'))
;            
}
$scope.dtOptions=$scope.buildTable();
$scope.buildColumns=函数(){
返回[
DTColumnBuilder.newColumn('id')。withTitle('id'),
DTColumnBuilder.newColumn('firstName')。withTitle('firstName'),
DTColumnBuilder.newColumn('lastName')。withTitle('lastName'),
DTColumnBuilder.newColumn('city')。带标题('city'),
DTColumnBuilder.newColumn('state')。withTitle('state'),
DTColumnBuilder.newColumn('zip')。withTitle('zip'),
DTColumnBuilder.newColumn('country')。带标题('country'),
DTColumnBuilder.newColumn('phone')。带标题('phone'),
DTColumnBuilder.newColumn('email')。带标题('email'))
];
}
$scope.dtColumns=$scope.buildColumns();
$scope.reloadData=reloadData;
$scope.dtInstance={};
函数重载数据(){
var=false;
$scope.dtInstance.reloadData(回调、重置分页);
}
函数回调(json){
log(json);
}
}
]);

或者只是动态创建表(.loadjquery可能很有用)

您使用的是动态加载还是任何类型的路由? 例如angularjs ngroute或某些框架

在这种情况下,它不能工作(不像你正在做的那样)。您可以按照以下指南或示例进行操作
http://jsfiddle.net/qu4a7j24/3/

<div ng-app='testTableApp'>

    <div class="container">
        <div ng-controller="mainTable">
            <form action="" method="POST" class="form-horizontal" role="form">
                <div class="form-group">
                    <legend>Filters</legend>
                </div>
                <div class="form-group">
                    <div class="col-sm-10 col-sm-offset-2">
                        <input type="text" value="0" ng-change='reloadData()' ng-model="start">
                        <input type="text" value="50" ng-change='reloadData()' ng-model="end">

                    </div>
                </div>
            </form>

            <table datatable="" dt-options="dtOptions" dt-columns="dtColumns" class="table table-striped table-bordered"></table>
        </div>
    </div>
</div>

var testTableApp = angular.module( 'testTableApp', ['ngRoute', 'ngResource', 'datatables', 'datatables.tabletools', 'datatables.bootstrap', 'datatables.fixedheader'] );
console.log( testTableApp );
testTableApp.controller("mainTable", 
[ '$scope', 'DTOptionsBuilder', 'DTColumnBuilder',
    function ( $scope, DTOptionsBuilder, DTColumnBuilder){
        $scope.dataSource = "http://dt.ishraf.com/ajax.php";
        $scope.start = 0;
        $scope.end = 5000;


        $scope.getDataSource = function(obj,prefix){
            var src = $scope.dataSource;

            var str = [];
            for(var p in obj) {
                if (obj.hasOwnProperty(p)) {
                    var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p];
                    str.push(typeof v == "object" ?
                    serialize(v, k) :
                    encodeURIComponent(k) + "=" + encodeURIComponent(v));
                }
            }
            return src + "?" + str.join("&");
        }

        var dsParams = {
            start : $scope.start,
            end : $scope.end
        }

        $scope.dsString = $scope.getDataSource( dsParams );


        $scope.buildTable = function(){
            return DTOptionsBuilder
                .newOptions()
                .withOption('ajax', {
                    // Either you specify the AjaxDataProp here
                    dataSrc: 'data',
                    url: $scope.dsString,
                    type: 'POST'
                }).
                withOption( 'lengthMenu', [
                    [10, 20, 50, 100, 150, 300, 500],
                    [10, 20, 50, 100, 150, 300, 500]
                ])                
                .withTableTools('bower_components/datatables-tabletools/swf/copy_csv_xls_pdf.swf')
                .withTableToolsButtons([
                    {
                        "sExtends": "copy",
                        "sButtonText": "<i class='fa fa-copy'></i>&nbsp;|&nbsp;Copy",
                        "fnInit": function (nButton, oConfig) {
                            $(nButton).addClass('btn btn-success');
                        }
                    },
                    {
                        "sExtends": "print",
                        "sButtonText": "<i class='fa fa-print'></i>&nbsp;|&nbsp;Print",
                        "fnInit": function (nButton, oConfig) {
                            $(nButton).addClass('btn btn-danger');
                        }
                    },
                    {
                        "sExtends": "csv",
                        "sButtonText": "<i class='fa fa-file-o'></i>&nbsp;|&nbsp;CSV",
                        "fnInit": function (nButton, oConfig) {
                            $(nButton).addClass('btn btn-primary');
                        }
                    },
                    {
                        "sExtends": "pdf",
                        "sButtonText": "<i class='fa fa-file-pdf-o'></i>&nbsp;|&nbsp;PDF",
                        "fnInit": function (nButton, oConfig) {
                            $(nButton).addClass('btn btn-warning');
                        }
                    }
                ])
                .withFixedHeader({
                    bottom: true
                })
                .withDOM('<"clear"><"#top.hidden-print"<".row"<".col-md-6"i><".col-md-6"f>><".row"<".col-md-6"l><".col-md-6"p>><"clear">T>rt')
                ;            
        }


        $scope.dtOptions = $scope.buildTable();

        $scope.buildColumns = function(){
            return [
                DTColumnBuilder.newColumn('id').withTitle('ID'),
                DTColumnBuilder.newColumn('firstName').withTitle('First name'),
                DTColumnBuilder.newColumn('lastName').withTitle('Last name'),
                DTColumnBuilder.newColumn('city').withTitle('city'),
                DTColumnBuilder.newColumn('state').withTitle('state'),
                DTColumnBuilder.newColumn('zip').withTitle('zip'),
                DTColumnBuilder.newColumn('country').withTitle('country'),
                DTColumnBuilder.newColumn('phone').withTitle('phone'),
                DTColumnBuilder.newColumn('email').withTitle('email')
            ];
        }

        $scope.dtColumns = $scope.buildColumns();


        $scope.reloadData = reloadData;
        $scope.dtInstance = {};

        function reloadData() {
            var resetPaging = false;
            $scope.dtInstance.reloadData(callback, resetPaging);
        }

        function callback(json) {
            console.log(json);
        }

    }
]);

过滤器
var testTableApp=angular.module('testTableApp',['ngRoute','ngresourcer
<div ng-app='testTableApp'>

    <div class="container">
        <div ng-controller="mainTable">
            <form action="" method="POST" class="form-horizontal" role="form">
                <div class="form-group">
                    <legend>Filters</legend>
                </div>
                <div class="form-group">
                    <div class="col-sm-10 col-sm-offset-2">
                        <input type="text" value="0" ng-change='reloadData()' ng-model="start">
                        <input type="text" value="50" ng-change='reloadData()' ng-model="end">

                    </div>
                </div>
            </form>

            <table datatable="" dt-options="dtOptions" dt-columns="dtColumns" class="table table-striped table-bordered"></table>
        </div>
    </div>
</div>

var testTableApp = angular.module( 'testTableApp', ['ngRoute', 'ngResource', 'datatables', 'datatables.tabletools', 'datatables.bootstrap', 'datatables.fixedheader'] );
console.log( testTableApp );
testTableApp.controller("mainTable", 
[ '$scope', 'DTOptionsBuilder', 'DTColumnBuilder',
    function ( $scope, DTOptionsBuilder, DTColumnBuilder){
        $scope.dataSource = "http://dt.ishraf.com/ajax.php";
        $scope.start = 0;
        $scope.end = 5000;


        $scope.getDataSource = function(obj,prefix){
            var src = $scope.dataSource;

            var str = [];
            for(var p in obj) {
                if (obj.hasOwnProperty(p)) {
                    var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p];
                    str.push(typeof v == "object" ?
                    serialize(v, k) :
                    encodeURIComponent(k) + "=" + encodeURIComponent(v));
                }
            }
            return src + "?" + str.join("&");
        }

        var dsParams = {
            start : $scope.start,
            end : $scope.end
        }

        $scope.dsString = $scope.getDataSource( dsParams );


        $scope.buildTable = function(){
            return DTOptionsBuilder
                .newOptions()
                .withOption('ajax', {
                    // Either you specify the AjaxDataProp here
                    dataSrc: 'data',
                    url: $scope.dsString,
                    type: 'POST'
                }).
                withOption( 'lengthMenu', [
                    [10, 20, 50, 100, 150, 300, 500],
                    [10, 20, 50, 100, 150, 300, 500]
                ])                
                .withTableTools('bower_components/datatables-tabletools/swf/copy_csv_xls_pdf.swf')
                .withTableToolsButtons([
                    {
                        "sExtends": "copy",
                        "sButtonText": "<i class='fa fa-copy'></i>&nbsp;|&nbsp;Copy",
                        "fnInit": function (nButton, oConfig) {
                            $(nButton).addClass('btn btn-success');
                        }
                    },
                    {
                        "sExtends": "print",
                        "sButtonText": "<i class='fa fa-print'></i>&nbsp;|&nbsp;Print",
                        "fnInit": function (nButton, oConfig) {
                            $(nButton).addClass('btn btn-danger');
                        }
                    },
                    {
                        "sExtends": "csv",
                        "sButtonText": "<i class='fa fa-file-o'></i>&nbsp;|&nbsp;CSV",
                        "fnInit": function (nButton, oConfig) {
                            $(nButton).addClass('btn btn-primary');
                        }
                    },
                    {
                        "sExtends": "pdf",
                        "sButtonText": "<i class='fa fa-file-pdf-o'></i>&nbsp;|&nbsp;PDF",
                        "fnInit": function (nButton, oConfig) {
                            $(nButton).addClass('btn btn-warning');
                        }
                    }
                ])
                .withFixedHeader({
                    bottom: true
                })
                .withDOM('<"clear"><"#top.hidden-print"<".row"<".col-md-6"i><".col-md-6"f>><".row"<".col-md-6"l><".col-md-6"p>><"clear">T>rt')
                ;            
        }


        $scope.dtOptions = $scope.buildTable();

        $scope.buildColumns = function(){
            return [
                DTColumnBuilder.newColumn('id').withTitle('ID'),
                DTColumnBuilder.newColumn('firstName').withTitle('First name'),
                DTColumnBuilder.newColumn('lastName').withTitle('Last name'),
                DTColumnBuilder.newColumn('city').withTitle('city'),
                DTColumnBuilder.newColumn('state').withTitle('state'),
                DTColumnBuilder.newColumn('zip').withTitle('zip'),
                DTColumnBuilder.newColumn('country').withTitle('country'),
                DTColumnBuilder.newColumn('phone').withTitle('phone'),
                DTColumnBuilder.newColumn('email').withTitle('email')
            ];
        }

        $scope.dtColumns = $scope.buildColumns();


        $scope.reloadData = reloadData;
        $scope.dtInstance = {};

        function reloadData() {
            var resetPaging = false;
            $scope.dtInstance.reloadData(callback, resetPaging);
        }

        function callback(json) {
            console.log(json);
        }

    }
]);