簡體   English   中英

DataTables警告:Json響應不起作用

[英]DataTables warning: Json Response not working

我正在嘗試使用IDcompany下拉列表過濾我的表格,該表格適用於我所有的選項,但出現以下消息的選項除外:

DataTables警告:table id = empTable-無效的JSON響應。 有關此錯誤的更多信息,請參見http://datatables.net/tn/1

我從調試器的“網絡”選項卡檢查了json響應,但此處未列出任何內容。 我以為問題出在我的查詢中,但是我回顯了它,並且如果我用Phpmyadmin編寫它,它可以正確構造和運行。

我在容器中有完全相同的代碼,並且工作得很好,但是在我的生產服務器中,它存在上述問題。 當我為狀態添加特定的過濾器時,盡管它可以正常運行,但僅適用於該特定過濾器。

我如何創建查詢:

(它適用於其他所有功能)

$empQuery = "select t.ID, c.name as IDcompany, v.name as IDvessel, w.name as IDwarehouse,
        t.orderno, s.name as IDstatus, su.name as IDsupplier, t.warehouseno, t.orderdate,
        t.datereceived, t.packages, t.weight, t.dimensions, r.name as shippingremarks,
        dan.name as IDdangerous, t.transportorderno, t.pacorefno, t.datedeliveredtovessel,
        t.destination, t.methodofdelivery, t.edt, t.description, t.description_color,
        t.orderdue, t.document, grp.groups
    from transactions t
    left join vessels v on t.IDvessel=v.ID
    left join companies c on t.IDcompany=c.ID
    left join statuses s on t.IDstatus=s.ID
    left join suppliers su on t.IDsupplier=su.ID
    left join warehouses w on t.IDwarehouse=w.ID
    left join remarks r on t.shippingremarks=r.ID
    left join yesno dan on t.IDdangerous=dan.ID
    left join admin_groups grp on t.groups=grp.ID
    WHERE t.deleted = 'No' "
    .$admQuery
    .$searchQuery
    ." order by ".$columnName." ".$columnSortOrder
    ." limit ".$row.",".$rowperpage; 

我如何創建我的json請求:

$(document).ready(function(){
      var dataTable = $('#empTable').DataTable({

          'processing': true,
          'serverSide': true,
          'serverMethod': 'post',
          //-- to remove the extra filter --
          'bFilter': false,
           //-- to move the sorting icon in the first row of the thead in the table --
          'bSortCellsTop': true,
          //-- to remove the sorting in action column --
          'columnDefs': [{
            'orderable': false,
            'targets': [0,1,25]
            }],

          // "scrollX": false,

          //'bAutoWidth': false,
          // 'fixedColumns': true,
          'oLanguage': {
            'oPaginate': {
              'sNext': 'Next'
            }
          },
          "aaSorting": [[2,'asc']],
          'async': false,
          "pageLength": 50,

          'ajax': {
              'url':'ajaxfile.php',
              // 'async':true,
              'data': function(data){
                  // Read values
                  var company = $('#searchByCustomer').val();
                  var vessel = $('#searchByVessel').val();
                  var warehouse = $('#searchByWarehouse').val();
                  var orderno = $('#searchByOrderNo').val();
                  var status = $('#searchByStatus').val();
                  var supplier = $('#searchBySupplier').val();
                  var warehouseno = $('#searchByStockNo').val();
                  var orderdate = $('#searchByOrderDate').val();
                  var datereceived = $('#searchByDateReceived').val();
                  var packages = $('#searchByCLL').val();
                  var weight = $('#searchByWeight').val();
                  var dimensions = $('#searchByPacoEyes').val();
                  var shippingremarks = $('#searchByRemark').val();
                  var IDdangerous = $('#searchByDGR').val();
                  var transportorderno = $('#searchByTransportNo').val();
                  var pacorefno = $('#searchByPacoRef').val();
                  var datedeliveredtovessel = $('#searchByDateDelivered').val();
                  var destination = $('#searchByDeliveredAt').val();
                  var methodofdelivery = $('#searchByMethodOfDelivery').val();
                  var edt = $('#searchByEstimatedDelivery').val();
                  var description = $('#searchByDescription').val();
                  var description_color = $('#searchByColor').val();
                  var orderdue = $('#searchByValue').val();
                  var groups = $('#searchByGroup').val();

                  // Append to data
                  data.searchByCustomer = company;
                  data.searchByVessel = vessel;
                  data.searchByWarehouse = warehouse;
                  data.searchByOrderNo = orderno;
                  data.searchByStatus = status;
                  data.searchBySupplier = supplier;
                  data.searchByStockNo = warehouseno;
                  data.searchByOrderDate = orderdate;
                  data.searchByDateReceived = datereceived;
                  data.searchByCLL = packages;
                  data.searchByWeight = weight;
                  data.searchByPacoEyes = dimensions;
                  data.searchByRemark = shippingremarks;
                  data.searchByDGR = IDdangerous;
                  data.searchByTransportNo = transportorderno;
                  data.searchByPacoRef = pacorefno;
                  data.searchByDateDelivered = datedeliveredtovessel;
                  data.searchByDeliveredAt = destination;
                  data.searchByMethodOfDelivery = methodofdelivery;
                  data.searchByEstimatedDelivery = edt;
                  data.searchByDescription = description;
                  data.searchByColor = description_color;
                  data.searchByValue = orderdue;
                  data.searchByGroup = groups;
              }
          },
          'columns': [
              { data: 'action' },
              { data: 'check'},
              { data: 'IDcompany' },
              { data: 'IDvessel' },
              { data: 'IDwarehouse' },
              { data: 'orderno' },
              { data: 'IDstatus' },
              { data: 'IDsupplier' },
              { data: 'warehouseno' },
              { data: 'orderdate' },
              { data: 'datereceived' },
              { data: 'packages' },
              { data: 'weight' },
              { data: 'dimensions' },
              { data: 'shippingremarks'},
              { data: 'IDdangerous' },
              { data: 'transportorderno' },
              { data: 'pacorefno' },
              { data: 'datedeliveredtovessel' },
              { data: 'destination' },
              { data: 'methodofdelivery' },
              { data: 'edt' },
              { data: 'description' },
              { data: 'description_color' },
              { data: 'orderdue' },
              { data: 'document' },
              { data: 'groups' },

          ]
      });


      $('#searchByCustomer').change(function(){
          dataTable.draw();
      });
      $('#searchByVessel').change(function(){
          dataTable.draw();
      });
      $('#searchByWarehouse').change(function(){
          dataTable.draw();
      });
      $('#searchByOrderNo').keyup(function(){
          dataTable.draw();
      });
      $('#searchByStatus').change(function(){
          dataTable.draw();
      });
      $('#searchBySupplier').change(function(){
          dataTable.draw();
      });
      $('#searchByStockNo').keyup(function(){
          dataTable.draw();
      });
      $('#searchByOrderDate').keyup(function(){
          dataTable.draw();
      });
      $('#searchByDateReceived').keyup(function(){
          dataTable.draw();
      });
      $('#searchByCLL').keyup(function(){
          dataTable.draw();
      });
      $('#searchByWeight').keyup(function(){
          dataTable.draw();
      });
      $('#searchByPacoEyes').keyup(function(){
          dataTable.draw();
      });
      $('#searchByRemark').change(function(){
          dataTable.draw();
      });
      $('#searchByDGR').change(function(){
          dataTable.draw();
      });
      $('#searchByTransportNo').keyup(function(){
          dataTable.draw();
      });
      $('#searchByPacoRef').keyup(function(){
          dataTable.draw();
      });
      $('#searchByDateDelivered').keyup(function(){
          dataTable.draw();
      });
      $('#searchByDeliveredAt').keyup(function(){
          dataTable.draw();
      });
      $('#searchByMethodOfDelivery').keyup(function(){
          dataTable.draw();
      });
      $('#searchByEstimatedDelivery').keyup(function(){
          dataTable.draw();
      });
      $('#searchByDescription').keyup(function(){
          dataTable.draw();
      });
      $('#searchByColor').change(function(){
          dataTable.draw();
      });
      $('#searchByValue').keyup(function(){
          dataTable.draw();
      });

      $('#searchByGroup').change(function(){
          dataTable.draw();
      });
      $("#actionReset").bind("click", function() {
          $("input[type=text]").val("");
          $("input[type=checkbox]").val("");
          $("#searchByGroup").val("");
          $("#searchByCustomer").val("");
          $("#searchByVessel").val("");
          $("#searchByWarehouse").val("");
          $("#searchByStatus").val("");
          $("#searchBySupplier").val("");
          $("#searchByRemark").val("");
          $("#searchByDGR").val("");
          $("#searchByColor").val("");

          dataTable.draw();
      });
  });

$ admQuery

if($admGroup == 'admin'){
   $admQuery="";
}else if ($admGroup == 'hamburg') {
   $admQuery=" and (grp.groups = '".$admGroup."' 
   or grp.groups = 'common') ";
}

$ searchQuery

if($searchByCustomer != ''){
  $searchQuery .= " and (t.IDcompany= '".$searchByCustomer."' ) ";
}
if($searchByVessel != ''){
  $searchQuery .= " and (t.IDvessel='".$searchByVessel."' ) ";
}
if($searchByWarehouse != ''){
  $searchQuery .= " and (t.IDwarehouse='".$searchByWarehouse."' ) ";
}
if($searchByOrderNo != ''){
  $searchQuery .= " and (t.orderno like '%".$searchByOrderNo."%' ) ";
}
...

這是呈現的mysql查詢的示例:

select t.ID, c.name as IDcompany, v.name as IDvessel, w.name as IDwarehouse, t.orderno,
       s.name as IDstatus, su.name as IDsupplier, t.warehouseno, t.orderdate,
       t.datereceived, t.packages, t.weight, t.dimensions, r.name as shippingremarks,
       dan.name as IDdangerous, t.transportorderno, t.pacorefno, t.datedeliveredtovessel,
       t.destination, t.methodofdelivery, t.edt, t.description, t.description_color,
       t.orderdue, t.document, grp.groups
from transactions t
left join vessels v on t.IDvessel=v.ID
left join companies c on t.IDcompany=c.ID 
left join statuses s on t.IDstatus=s.ID 
left join suppliers su on t.IDsupplier=su.ID 
left join warehouses w on t.IDwarehouse=w.ID 
left join remarks r on t.shippingremarks=r.ID 
left join yesno dan on t.IDdangerous=dan.ID
left join admin_groups grp on t.groups=grp.ID
WHERE t.deleted = 'No'
  and (grp.groups = 'hamburg' or grp.groups = 'common')
  and (t.IDcompany= '84' )
  and (t.IDstatus='3' )
order by IDcompany asc 
limit 0,50

這是我得到的,但是Ajax響應作為錯誤消息返回。

我已經解決了問題。 這不是服務器端或ajax問題,而是數據庫問題。 一些記錄具有特殊字符,例如'–'(德語破折號),查詢無法正確讀取它們並導致錯誤。

我用普通破折號“-”替換了這些記錄,並且可以正常工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM