douyu2817 2012-09-04 16:59
浏览 43
已采纳

如果HTML是通过$ .get(..)发送的,则jquery数据表格式不正确

If in content.php I do not fill the table with the data, then I can see properly formatted jquery data table. However, if I fill it with the data (I tried both DB data and manual input of some random numbers), it is not formatted anymore and looks like a hell. Could it happen that $.get(..) (used in test.php) does not work properly in this example?

test.php

    $(document).ready(function() {
        loadContent();
    });

    function loadContent() {
                            $.get('modules/mod_scheduler/content.php', function(data) {
                                $('#table').html(data);
                            });     
    }

<div id="table"></div>

content.php

<?php
    include_once '../../include/connect_db.php';

    $query = "SELECT * FROM `TestTable`";
    $result=execute_query($query);

?>



    <table id="newspaper-b" border="0" cellspacing="2" cellpadding="2" width = "100%">
                        <thead>
                            <tr>
                                <th scope="col">Flight Num</th>
                                <th scope="col">Appearance Time</th>
                                <th scope="col">Target Time</th>
                                <th scope="col"></th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php while($row=mysql_fetch_assoc($result)) {
                                        $flightNum=$row['flightNum'];
                                        $appearanceTime=$row['appearanceTime'];
                                        $targetTime=$row['targetTime'];
                            ?>
                            <tr>
                                <td><?php echo $flightNum; ?></td>
                                <td>

                                        <?php echo $appearanceTime;?>

                                </td>
                                <td>

                                        <?php echo $targetTime;?>

                                </td>

                                <td id="<?php echo $flightNum; ?>">
                                    <div>
                                        <img src='modules/images/edit.png' alt='Edit' />
                                    </div>
                                </td>
                            </tr>
                            <?php }?>
                        </tbody>
    </table>

Of course, I have also defined the following:

<link type="text/css" rel="stylesheet" href="modules/mod_scheduler/css/demo_table.css"/>
<link type="text/css" rel="stylesheet" href="modules/mod_scheduler/css/demo_page.css"/>
<link type="text/css" rel="stylesheet" href="modules/mod_scheduler/css/demo_table_jui.css"/>

<script type="text/javascript" src="modules/mod_scheduler/js/dataTable/jquery-ui.js"></script>
<script type="text/javascript" src="modules/mod_scheduler/js/dataTable/jquery.dataTables.js"></script>

<script language="javascript" type="text/javascript" src="modules/mod_scheduler/js/jqplot/plugins/jqplot.pointLabels.js"></script>
  • 写回答

2条回答 默认 最新

  • dsb238100 2012-09-04 21:14
    关注

    You are returning a table, but you are not calling dataTable() on it that I can see. The way the DataTables plugin works, you typically call the dataTable() on a table. I can't recall what should happen with "arbitrary" style sheets (whatever styles you've set for the table), but certainly if you're using jQuery UI (which it looks like you are), it won't look right until you call the function, thereby adding all the necessary classes for jQuery UI theme. You could return those classes already in the table, but currently you are not.

    Since you are doing this server-side, I would take it a step further and return JSON-formatted data for the table instead of a whole bunch of table markup. That's the more elegant and manageable way of using DataTables.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算