繁体   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