2012-09-04 32 views
0

如果在content.php中我沒有填充表中的數據,那麼我可以看到格式正確的jquery數據表。但是,如果我填充數據(我嘗試了數據庫數據和一些隨機數字的手動輸入),它不會被格式化,看起來像是一個地獄。在這個例子中,$.get(..)(在test.php中使用)不能正常工作嗎?

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> 

當然,我還定義如下:

<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> 
+0

你是什麼意思下「看起來像地獄」?你有沒有試過把它直接放在test.php中? –

+0

我在content.php中看不到任何真的不好的東西。除了可能是id =「<?php echo $ flightNum;?>」 - 但是如果$ flightNum只是一個數字 - 在這裏應該沒問題。你能否展示一個外觀好壞的屏幕? –

+0

如果手動和抓取的數據沒有得到正確的格式那麼可能的原因將是CSS或JQuery中的衝突。 – djadmin

回答

1

您正在退回一張表格,但您不打電話給我看到的dataTable()。 DataTables插件的工作方式是,您通常在桌面上調用dataTable()。我不記得「任意」樣式表(無論您爲表格設置了什麼樣式)會發生什麼情況,但是當然如果您使用jQuery UI(它看起來像您),它看起來不正確直到你調用函數,從而爲jQuery UI主題添加所有必需的類。你可以返回已經在表格中的那些類,但是目前你沒有。

既然你正在做這個服務器端,我會更進一步,並返回表格的JSON格式的數據而不是一堆表標記。這是使用DataTable更優雅和可管理的方式。

1

您可以重新加載樣式表ajax更新,但它顯示uld auto在新元素上應用CSS樣式。

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

function loadContent() { 
    $.get('modules/mod_scheduler/content.php', function(data) { 
     $('#table').html(data); 
     var randomString = '?r=' + Math.random(); 
     $('link[rel="stylesheet"]').each(function() { 
      this.href = this.href.replace(/\?.*|$/, randomString); 
     }); 
    }); 
} 

如果還是不行,請嘗試從AJAX生成的內容適用於該table DIV手動,也許在你的CSS,你有一個錯誤。有些//的意見。我做出那樣的錯誤..

+0

嗯,這並沒有解決問題。 –

+0

你真的認爲這是問題嗎?如何可以幫助所有? –

+0

它有助於刷新CSS應用於HTML,@YouKuper我已修改並在'$ .get'內添加了重新加載..現在嘗試 –