首页 > 解决方案 > 无法使用 Ajax 将数据搜索到数据表中 - Codeigniter

问题描述

大家好,我正在创建一个门户网站。我想添加显示数据表。我为此使用 Datatable 插件,但我遇到了一些问题。请帮我解决一下这个。

这是我的控制器代码

public function fetchTeams() {
    $data = $this->Teams_model->getAllTeams();
    echo json_encode(array("data" => $data));
}

我的 HTML 视图

<div class="card-body">
    <table id="teamDatatable" class="display table table-bordered table-hover" width="100%">
        <thead>
            <tr>
                <th>Employee name</th>
                <th>Email</th>
                <th>Gender</th>
                <th>Salary</th>
                <th>City</th>
            </tr>
        </thead>
    </table>
</div>

我的模特

public function getAllTeams() {
    $query = $this->db->get("teams");
    return $query->result_array();
    $query1 = $this->db->get('Teams');
    $data1 = $query->num_rows();
    $response = array(
        "iTotalRecords" => $data1,
        "aaData" => $data
    );

    return $response;
}

我的观点在此处输入图像描述

我的观点在此处输入图像描述

没有记录在此处输入图像描述

标签: phpajaxcodeigniterdatatable

解决方案


希望这会有所帮助 在此处检查我的服务器端 codeigniter 脚本 服务器端数据表 codeigniter


推荐阅读