datatables 1.10.12 fails to compose Ajax request properly at random intervals with no apparent cause

datatables 1.10.12 fails to compose Ajax request properly at random intervals with no apparent cause

The following DataTables implementation fails randomly and unpredictably. The Table will be correctly rendered about half the time, and then fail with no change in parameters by simply refreshing the same page in the browser. Further refresh of the page after it has failed can also result in a successfully rendered table.

The Misbehavior is the same on all major browsers. When the failure occurs, unminified jquery.dataTables.js throws an error at line 4108 (for ( var i=0, ien=data.length ; i<ien ; i++ ) ) with 'cannot read property 'length' of undefined'. This failure causes the request string to be malformed (6 elements present in the request rather than the expected 7 (the 'draw' array is not present)) which in turn causes the server-side ssp.class.php to generate an invalid query and the Db server to throw an error which is echoed back to the client browser and spawns a dialogue with the following text:

"DataTables warning: table id=MyDataTable - An SQL error occurred: SQLSTATE[42000]: Syntax error or access violation: 1064 you have an error your SQL syntax...near 'LIMIT 0,10' at line..."

The datatables implementation is nearly identical to the 'Server Side' example with no significant deviations from that example beyond the DataSource and Column definitions being altered. DataSource is ~110K rows table on MYSQL 5.7.10 server (running local to the machine), datasource PHP (v5.6). I have tried various versions of JQuery (1.21 through 3.1.1) multiple versions of DataTables with no change.

I have experimented with all the suggestions (character set, datasource and Ajax data properties explicitly defined (see commented out lines below) which I can find in this forum and other sources to deal with similar errors to no effect.

Anyone have any ideas why the jquery.dataTables.js would succeed one moment, and then fail another moment, and then succeed again after simply refreshing the same page?

```
JSONClient.php

Id Date Order Type Item Price Quantity Fee
$(document).ready(function () { $('#myDataTable').DataTable({ "responsive": true, "processing": true, "serverSide": true, "paging": true, "ajax": "/TestArea/JSONSource.php" //"sAjaxDataProp": "data", //"dataSrc": "data" }); });

JSONSource.php

<?php
//Db Table to execute against
$table = 'ObscuredTableName';
// Table's primary key
$primaryKey = 'Id';
//Table Columns to Db Fields mapping
$columns = array(
array('db' => 'Id','dt' => 0 ),
array('db' => 'Date','dt' => 1 ),
array('db' => 'OrderType','dt' => 2 ),
array('db' => 'Item','dt' => 3 ),
array('db' => 'Price','dt' => 4 ),
array('db' => 'Quantity','dt' => 5 ),
array('db' => 'Fee','dt' => 6)
);
// SQL server connection information
$sql_details = array(
'user' => 'ObscuredUserName',
'pass' => 'ObscuredPassword',
'db' => 'ObscuredSchemaName',
'host' => 'localhost');

require('ssp.class.php');
echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);

<?php > ``` ?>

This question has an accepted answers - jump to answer

Answers

This discussion has been closed.