Php 显示0个条目并搜索不工作的数据表

Php 显示0个条目并搜索不工作的数据表,php,ajax,datatable,datatables,Php,Ajax,Datatable,Datatables,有人能帮我写代码吗?我可以显示来自json的数据,但每次我在datatable上使用搜索时,它总是给我一个除此之外没有数据的选项。分页被禁用,并且显示0个条目,即使我在表上有数据 这是我的代码: ajax.js var url = '../../class/functions.php'; function show_employee() { var data = { action : 'Show Employee Table' }; $.ajax({ type:

有人能帮我写代码吗?我可以显示来自json的数据,但每次我在datatable上使用搜索时,它总是给我一个除此之外没有数据的选项。分页被禁用,并且显示0个条目,即使我在表上有数据

这是我的代码:

ajax.js

var url = '../../class/functions.php';

function show_employee() {
    var data = { action : 'Show Employee Table' };
    $.ajax({
        type: 'POST', url: url, data: data, cache: false,
        success:function(data) {
            $('#show_employee_table').html(data);
        }
    });
}
config.php

<?php
    session_start();
    ob_start();
    include 'class.php';
    //include 'init.php';
    $data = new db();
?>
<?php 
    include 'config.php';

    switch($_POST['action']) {
        case 'Show Employee Table':
            $data->show_employee_table();
        break;
    }
?>
<?php
    include 'controller.php';

    class db extends Controller {
        //Get all employees
        public function get_employee() {
            $query = $this->db->query("SELECT * FROM tbl_try");
            return $query;
        }

        public function show_employee_table() {
            foreach($this->get_employee() as $row): ?>
                <?php $data = $row; ?>
                <?php $employee_status = ($row['employee_status'] == "Active") ? '<span class="badge badge-success">Active</span>' : '<span class="badge badge-danger">Not Active</span>';?>
                <tr>    
                    <td><?=$row['employee_number']?></td>
                    <td><?=$row['employee_surname']?>, <?=$row['employee_firstname']?></td>
                    <td><?=$row['employee_email']?></td>
                    <td><?=$row['employee_contact']?></td>
                    <td><?=$employee_status?></td>
                    <td style="text-align:center"><a onclick="modal_edit_status('<?=$row['employee_id']?>')" style="cursor:pointer" alt="Status"><i class="icon-eye"></i></a></td>
                    <td style="text-align:center"><a onclick="modal_delete_employee('<?=$row['employee_id']?>')"style="cursor:pointer" alt="Remove"><i class="icon-trash"></i></a></td>
                    <td style="text-align:center"><a onclick="edit_employee_by_id('<?=$row['employee_id']?>')" style="cursor:pointer" alt="Edit"><i class="icon-pencil"></i></a></td>
                </tr>
            <?php endforeach;
        }

    }

?>
<div class="card">
                        <table class="table datatable-button-print-basic">
                            <thead>
                                <tr>
                                    <th>Employee Number</th>    
                                    <th>Name</th>
                                    <th>Email</th>
                                    <th>Contact</th>
                                    <th>Status</th>
                                    <th colspan=3 class="text-center">Actions</th>
                                </tr>
                            </thead>
                            <tbody id="show_employee_table" ><!--content will go here--></tbody>
                        </table>            
                    </div>

functions.php

<?php
    session_start();
    ob_start();
    include 'class.php';
    //include 'init.php';
    $data = new db();
?>
<?php 
    include 'config.php';

    switch($_POST['action']) {
        case 'Show Employee Table':
            $data->show_employee_table();
        break;
    }
?>
<?php
    include 'controller.php';

    class db extends Controller {
        //Get all employees
        public function get_employee() {
            $query = $this->db->query("SELECT * FROM tbl_try");
            return $query;
        }

        public function show_employee_table() {
            foreach($this->get_employee() as $row): ?>
                <?php $data = $row; ?>
                <?php $employee_status = ($row['employee_status'] == "Active") ? '<span class="badge badge-success">Active</span>' : '<span class="badge badge-danger">Not Active</span>';?>
                <tr>    
                    <td><?=$row['employee_number']?></td>
                    <td><?=$row['employee_surname']?>, <?=$row['employee_firstname']?></td>
                    <td><?=$row['employee_email']?></td>
                    <td><?=$row['employee_contact']?></td>
                    <td><?=$employee_status?></td>
                    <td style="text-align:center"><a onclick="modal_edit_status('<?=$row['employee_id']?>')" style="cursor:pointer" alt="Status"><i class="icon-eye"></i></a></td>
                    <td style="text-align:center"><a onclick="modal_delete_employee('<?=$row['employee_id']?>')"style="cursor:pointer" alt="Remove"><i class="icon-trash"></i></a></td>
                    <td style="text-align:center"><a onclick="edit_employee_by_id('<?=$row['employee_id']?>')" style="cursor:pointer" alt="Edit"><i class="icon-pencil"></i></a></td>
                </tr>
            <?php endforeach;
        }

    }

?>
<div class="card">
                        <table class="table datatable-button-print-basic">
                            <thead>
                                <tr>
                                    <th>Employee Number</th>    
                                    <th>Name</th>
                                    <th>Email</th>
                                    <th>Contact</th>
                                    <th>Status</th>
                                    <th colspan=3 class="text-center">Actions</th>
                                </tr>
                            </thead>
                            <tbody id="show_employee_table" ><!--content will go here--></tbody>
                        </table>            
                    </div>

class.php

<?php
    session_start();
    ob_start();
    include 'class.php';
    //include 'init.php';
    $data = new db();
?>
<?php 
    include 'config.php';

    switch($_POST['action']) {
        case 'Show Employee Table':
            $data->show_employee_table();
        break;
    }
?>
<?php
    include 'controller.php';

    class db extends Controller {
        //Get all employees
        public function get_employee() {
            $query = $this->db->query("SELECT * FROM tbl_try");
            return $query;
        }

        public function show_employee_table() {
            foreach($this->get_employee() as $row): ?>
                <?php $data = $row; ?>
                <?php $employee_status = ($row['employee_status'] == "Active") ? '<span class="badge badge-success">Active</span>' : '<span class="badge badge-danger">Not Active</span>';?>
                <tr>    
                    <td><?=$row['employee_number']?></td>
                    <td><?=$row['employee_surname']?>, <?=$row['employee_firstname']?></td>
                    <td><?=$row['employee_email']?></td>
                    <td><?=$row['employee_contact']?></td>
                    <td><?=$employee_status?></td>
                    <td style="text-align:center"><a onclick="modal_edit_status('<?=$row['employee_id']?>')" style="cursor:pointer" alt="Status"><i class="icon-eye"></i></a></td>
                    <td style="text-align:center"><a onclick="modal_delete_employee('<?=$row['employee_id']?>')"style="cursor:pointer" alt="Remove"><i class="icon-trash"></i></a></td>
                    <td style="text-align:center"><a onclick="edit_employee_by_id('<?=$row['employee_id']?>')" style="cursor:pointer" alt="Edit"><i class="icon-pencil"></i></a></td>
                </tr>
            <?php endforeach;
        }

    }

?>
<div class="card">
                        <table class="table datatable-button-print-basic">
                            <thead>
                                <tr>
                                    <th>Employee Number</th>    
                                    <th>Name</th>
                                    <th>Email</th>
                                    <th>Contact</th>
                                    <th>Status</th>
                                    <th colspan=3 class="text-center">Actions</th>
                                </tr>
                            </thead>
                            <tbody id="show_employee_table" ><!--content will go here--></tbody>
                        </table>            
                    </div>

, 

我没有看到你在任何地方使用“数据表”?您似乎只需要输出一个普通的HTML表。搜索在哪里,这是您似乎在问的问题?您是否在某处使用您的
class.php
?操作是的,我在@kerbh0lz使用它进行调试,简化事情,一旦它起作用,就会增加复杂性。对于您的代码,删除AJAX和POST,只需使用普通GET即可使用浏览器查看错误消息。确保为PHP完全打开了错误报告,并确保每个条件都有最后的选择,例如
开关
,它应该有一个默认值,可能是
抛出的