dongyoucha0645 2017-04-25 04:43
浏览 106

使用ajax jquery填充数据时,分页和搜索框不会显示在bootstrap数据表中

When i display data in bootstrap datatable using ajax jquery then pagination and search box is not display.so how to solve this problem

My html sample code is here.

 <div class="row" style="margin-top: 2em;">
     <div class="panel panel-white">
       <div class="panel-heading clearfix">

       </div>
       <div class="panel-body">
           <div id="live_data" >
             //data table display here                         
           </div>
       </div>
    </div>

And my ajax file code is here

    <?php

    $output='';     
    $output.='  <div class="table-responsive">
                   <table id="example" class="table table-striped table-
                     bordered" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Age</th>
            <th>Start date</th>
            <th>Salary</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Age</th>
            <th>Start date</th>
            <th>Salary</th>
        </tr>
    </tfoot>
    <tbody>
        <tr>
            <td>Tiger Nixon</td>
            <td>System Architect</td>
            <td>Edinburgh</td>
            <td>61</td>
            <td>2011/04/25</td>
            <td>$320,800</td>
        </tr>
        <tr>
            <td>Garrett Winters</td>
            <td>Accountant</td>
            <td>Tokyo</td>
            <td>63</td>
            <td>2011/07/25</td>
            <td>$170,750</td>
        </tr>
        <tr>
            <td>Ashton Cox</td>
            <td>Junior Technical Author</td>
            <td>San Francisco</td>
            <td>66</td>
            <td>2009/01/12</td>
            <td>$86,000</td>
        </tr>                                                        
    </tbody>
</table>
</div>';
echo $output;
?>

And my jquery function is here

 getcamera();
        function getcamera(){
            $.ajax({
                type:"POST",
                url:'../ajaxfiles/ajax_getcamera.php',
                success:function(data){
                    $('#live_data').html(data);

                }
            });
        }


This above code is work properly but search box and pagination is not display

so how to solve that problem???

  • 写回答

1条回答 默认 最新

  • drpiqlzrh62917192 2017-04-25 04:48
    关注
     `getcamera();
        function getcamera(){
            $.ajax({
                type:"POST",
                url:'../ajaxfiles/ajax_getcamera.php',
                success:function(data){
                    $('#live_data').html(data);
                     $('#example').DataTable();// Add this line.
                }
            });
        }`
    

    Above code will work. This is not the best solution. For good ajax implementation you can see example usages at https://datatables.net/examples/ajax/simple.html And https://datatables.net/examples/server_side/simple.html

    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)