如何解决此Datatable错误?

时间:2018-08-15 09:01:36

标签: json ajax codeigniter

Datatables

您能帮我解决数据表中的此类错误吗?  预先谢谢你

这是我使用ajax和json的数据表代码 使用datatables函数在另一个页面中显示数据

   $.ajax({
         type: 'ajax',
         method: 'get',
         url: '<?php echo base_url()?>app/code_of_discipline/showallcod',
         data: {
             company_id: company_id,
             location_id: location_id
         },
         async: false,
         dataType: 'json',
         success: function(data) {
             var html = '';
             var i;

         for (i = 0; i < data.length; i++) {

             html += '<table class="table table-bordered table-responsive" id="example1">' +
                 '<thead tyle="display: none;">' +
                 '<tr style="display: none;">' +
                 '<th style="visibility: hidden;display: none;">numbering</th>' +
                 '<th style="visibility: hidden;display: none;">title</th>' +

                 '</tr>' +
                 '</thead>' +
                 '<tbody>' +
                 '<tr>' +
                 '<td style="text-align:left;">' + data[i].numbering + '</td>' +
                 '<td style="text-align:left;">' + data[i].title + '<span colspan="2" class="col-xs-10" style="text-overflow: ellipsis;  white-space: nowrap; width: 655px; overflow: hidden; display: inline-block;">' + data[i].description + '...<a onclick="view_disob(' + data[i].cod_id + ');" data-toggle="tooltip" data-placement="right" title="CLick to View this ' + data[i].numbering + ' Code of Discipline"><strong>see more</strong>' + '</a>' +
                 '</span>' +
                 '</td>' +

                 '</tr>' +

                 '</tbody>' +
                 '</table>';
         }
         $('#showdata').html(html);

     },
     error: function() {
         alert('Could not get data');
     }

 });
 $("#example1").DataTable();

1 个答案:

答案 0 :(得分:0)

table标签从Ajax中取出。

 $.ajax({
         type: 'ajax',
         method: 'get',
         url: '<?php echo base_url()?>app/code_of_discipline/showallcod',
         data: {
             company_id: company_id,
             location_id: location_id
         },
         async: false,
         dataType: 'json',
         success: function(data) {
             var html = '<table class="table table-bordered table-responsive" id="example1">' +
                 '<thead tyle="display: none;">' +
                 '<tr style="display: none;">' +
                 '<th style="visibility: hidden;display: none;">numbering</th>' +
                 '<th style="visibility: hidden;display: none;">title</th>' +

                 '</tr>' +
                 '</thead>' +
                 '<tbody>';
             var i;

         for (i = 0; i < data.length; i++) {

             html +=  '<tr>' +
                 '<td style="text-align:left;">' + data[i].numbering + '</td>' +
                 '<td style="text-align:left;">' + data[i].title + '<span colspan="2" class="col-xs-10" style="text-overflow: ellipsis;  white-space: nowrap; width: 655px; overflow: hidden; display: inline-block;">' + data[i].description + '...<a onclick="view_disob(' + data[i].cod_id + ');" data-toggle="tooltip" data-placement="right" title="CLick to View this ' + data[i].numbering + ' Code of Discipline"><strong>see more</strong>' + '</a>' +
                 '</span>' +
                 '</td>' +
                 '</tr>' ;                 
         }
         html = '</tbody>' + '</table>';
         $('#showdata').html(html);
          $("#example1").DataTable();
     },
     error: function() {
         alert('Could not get data');
     }
 });