程序go 2018-11-06 12:21 采纳率: 100%
浏览 37

使用ajax获取数据表数据

I am trying to display dataTable data using ajax but it didn't work.

This is my jquery code :

$('#example').DataTable({
                ajax: {
                    type: 'GET',
                    url: 'data.php',
                    success: function (msg) {
                        $("#tbody_example").html(msg);
                    }
                }
            });

This is my data.php page :

    <?php   echo '<td>Name</td>
            <td>Position</td>
            <td>Office</td>
            <td>Extn.</td>
            <td>Start date</td>
            <td>Salary</td>'; ?>

and This is my dataTable :

 <table id="example" class="display" style="width:100%">
    <thead>
        <tr>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Extn.</th>
            <th>Start date</th>
            <th>Salary</th>
        </tr>
    </thead>
    <tbody id="tbody_example">

    </tbody>
    <tfoot>
        <tr>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Extn.</th>
            <th>Start date</th>
            <th>Salary</th>
        </tr>
    </tfoot>
</table>

My dataTable still empty and I get MOCK GET: data.php as error. Any one can help me.

  • 写回答

3条回答 默认 最新

  • 程序go 2018-11-06 12:33
    关注

    Try the below thing, It should work

    In php file

    $content = "<td>Name</td>
                <td>Position</td>
                <td>Office</td>
                <td>Extn.</td>
                <td>Start date</td>
                <td>Salary</td>";
    
    $return["json"] = json_encode();
    echo json_encode($return);
    

    In ajax

    ajax: {
             type: 'GET',
             url: 'data.php',
             success: function (msg) {
                   $("#tbody_example").html(msg["json"]);
             }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测