duanguangsong2380 2017-09-17 04:17
浏览 70

使用Jquery Ajax PHP实时显示数据表

I just want to know how can i fetch the design of the datatables of my table. Because the filter and the pagination of the table is not working. Heres my code.

i have this plugin in my

  <link rel="stylesheet" href="../assets/vendor/datatables-bootstrap/dataTables.bootstrap.css">
  <link rel="stylesheet" href="../assets/vendor/datatables-fixedheader/dataTables.fixedHeader.css">
  <link rel="stylesheet" href="../assets/vendor/datatables-responsive/dataTables.responsive.css">
  <link rel="stylesheet" href="../assets/vendor/datatables-bootstrap/dataTables.bootstrap.css">
  <link rel="stylesheet" href="../assets/vendor/datatables-fixedheader/dataTables.fixedHeader.css">
  <link rel="stylesheet" href="../assets/vendor/datatables-responsive/dataTables.responsive.css">

  <script src="../assets/vendor/datatables/jquery.dataTables.min.js"></script>
  <script src="../assets/vendor/datatables-fixedheader/dataTables.fixedHeader.js"></script>
  <script src="../assets/vendor/datatables-bootstrap/dataTables.bootstrap.js"></script>
  <script src="../assets/vendor/datatables-responsive/dataTables.responsive.js"></script>
  <script src="../assets/vendor/datatables-tabletools/dataTables.tableTools.js"></script>

display

<div id="table_data" >
</div>

script

    fetch_data();

 function fetch_data()
 {
  var action = "fetch";
  $.ajax({
   url:"table/serviceTypeTable.php",
   method:"POST",
   data:{action:action},
   success:function(data)
   {
    $('#table_data').html(data);
   }
  })
 }

query for fetch:

if(isset($_POST["action"]))
{
 if($_POST["action"] == "fetch")
 {
  $qry = mysql_query("select * from services_type")or die(mysql_error());
  $count = mysql_num_rows($qry);
  $output = '
    <table class="table table-hover dataTable table-striped width-full"  data-plugin="dataTable">
        <thead>
            <th>Services Types</th>
            <th>Action</th>
        </thead>
  ';
  while($row = mysql_fetch_array($qry))
  {
   $services_type_id = $row['services_type_id'];
   $output .= '
    <tbody>
    <tr>
        <td>'.$row['services_type_name'].'</td>
        <td style="text-align:center;">
            <a href="javascript:void(0);" onclick="editServiceType('.$services_type_id.')" data-toggle="modal" class="btn btn-success"><i class="fa fa-edit"></i></a>
        </td>
    </tr>
    </tbody>
   ';
  }
  $output .= '</table>';
  echo $output;
 }
}

my problem is the datatables design is not working. that's all thanks :)

  • 写回答

1条回答 默认 最新

  • dqrl3595 2017-09-17 05:26
    关注

    I figured it out. I just put this script in query fetch at the button after the :)

    <script>
       $("#table").dataTable({
       });
    </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的