weixin_33693070 2015-11-12 11:50 采纳率: 0%
浏览 11

将Ajax用于数据表

I am using datatable now and I am unable to receive the data from my ajax file to datatable codes.

My codes are as follows:

AJAX

<?php
function functionClass($id) {
        // create sql query
     $Class = "SELECT class.id, class.day, class.start_time, class.end_time, subject.subject_name, tutor.tutor_id, tutor.tutor_name AS t_name, classroom.room
     FROM class, subject, tutor, classroom
     WHERE class.subject_id = subject.id
     AND class.tutor_id = tutor.id
     AND class.classroom_id = classroom.id";

     //$resultClass = mysqli_query($link, $viewClass) or die(mysqli_error($link));

}
?>

Javascript

<script>
`$(document).ready( {`
    $.fn.dataTable.TableTools.defaults.aButtons = [ "csv" ];
    $('.datatable').DataTable({
        responsive: true,
        serverSide: true,
        processing: true,       
        lengthMenu: [ [10, 25, 50, -1], [10, 25, 50, "All"] ],
        ajax: {
            url: "http://localhost/FYP/dt/class/",
            type: "POST",
            data: {
                method: "get"     
                }
            }, 
            columns : [
                {
                    data: "id",
                    render: function(data, type, row) {
                        return <?php echo $row['id'] ?> + row.id + '/">' + data + '</a>';                    
                    }
]   

My datatable method is

<div class="container">
    <div class="btn-toolbar" role="toolbar">
        <a href="addNewClass.php" class="btn btn-success"><span class="fa fa-fw fa-plus"></span> New Class</a>    
    </div>        
    <table class="table table-hover table-striped datatable" width="100%">
        <thead>
            <tr> 
                <th class="all">S/N</th>
                <th class="min-tablet-l">Day</th>
                <th class="min-tablet-l">Start Time</th>
                <th class="min-tablet-l">End Time</th>
                <th class="min-tablet-l">Subject</th>
                <th class="min-tablet-l">Staff ID</th>                
                <th class="min-tablet-l">Tutor</th>
                <th class="min-tablet-l">Classroom</t                  
            </tr>
        </thead>
        <tbody>
        <tbody>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tbody>
        </tbody>
        <tfoot>
            <tr> 
                <th>S/N</th>
                <th>Day</th>
                <th>Start Time</th>
                <th>End Time</th>
                <th>Subject</th>
                <th>Staff ID</th>                
                <th>Tutor</th>
                <th>Classroom</th>                
            </tr>
        </tfoot>            
    </table>
</div>  

UPDATE: I have resolved most issue now when I am initialising the table I get this error "3. Warning: Cannot reinitialise Data" A look into my console it tells me POST http://localhost/FYP/dt/functionClass/ 404 (Not Found)

  • 写回答

2条回答 默认 最新

  • csdnceshi62 2015-11-12 11:55
    关注

    first you should check the ajax syntax .you a an error:add , after url.

    url: "http://localhost/FYP/dt/class/",
            type: "POST",
    
    评论

报告相同问题?

悬赏问题

  • ¥15 三菱变频器模块怎么检测触发
  • ¥15 在C#方法中使用了.Refresh();刷新了控件,但是不是最新值
  • ¥30 求一下解题思路,完全不懂。
  • ¥30 关于#硬件工程#的问题:求一下解题思路
  • ¥15 运筹学对偶单纯行法构造扩充问题
  • ¥20 XP系统的老电脑一开机就提示找不到rundll.exe,付费求解
  • ¥15 milvus查询出来的score怎么转换成0-1之间的相似性
  • ¥15 多ip服务器站群如何搭建l2tp服务器
  • ¥15 lvgl V9移植到linux开发板
  • ¥15 VB.net中在窗体中创建一个button控件来关闭窗体,但是提示错误,我该怎么办