DataTables Invalid JSON response -
i'm having trouble datatables.
i'm trying use server-side script make data loading faster in project, keep getting errors.
when load page, first error is:
datatables.min.js:86 uncaught error: datatables warning: table id=lista_pedidos - invalid json response. more information error, please see http://datatables.net/tn/1 @ k (datatables.min.js:86) @ object.error (datatables.min.js:48) @ (jquery.js:2) @ object.firewith [as rejectwith] (jquery.js:2) @ (jquery.js:4) @ xmlhttprequest.<anonymous> (jquery.js:4)
when type on search field same error in logs , in tab "network" following error:
<br /> <b>notice</b>: undefined offset: 0 in <b>c:\wamp64\www\prevmais\sistema\app\server\ssp.class.php</b> on line <b>116</b><br /> <br /> <b>notice</b>: undefined offset: 0 in <b>c:\wamp64\www\prevmais\sistema\app\server\ssp.class.php</b> on line <b>162</b><br /> <br /> <b>notice</b>: undefined offset: 1 in <b>c:\wamp64\www\prevmais\sistema\app\server\ssp.class.php</b> on line <b>162</b><br /> <br /> <b>notice</b>: undefined offset: 0 in <b>c:\wamp64\www\prevmais\sistema\app\server\ssp.class.php</b> on line <b>176</b><br /> <br /> <b>notice</b>: undefined offset: 1 in <b>c:\wamp64\www\prevmais\sistema\app\server\ssp.class.php</b> on line <b>176</b><br /> {"error":"an sql error occurred: sqlstate[42000]: syntax error or access violation: 1064 have error in sql syntax; check manual corresponds mysql server version right syntax use near 'limit 0, 100' @ line 5"}
these scripts:
1) initializing datatables:
$(document).ready(function() { $.fn.datatable.ext.errmode = 'throw'; $('#lista_pedidos').datatable( { "processing": true, "serverside": true, "ajax": { url: "/app/server/server_side.php", datatype: 'json' } });
2) server-side script:
<?php header('content-type: application/json'); /* * datatables example server-side processing script. * * please note script intentionally extremely show how * server-side processing can implemented, , shouldn't used * basis large complex system. suitable simple use cases * learning. * * see http://datatables.net/usage/server-side full details on server- * side processing requirements of datatables. * * @license mit - http://datatables.net/license_mit */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * easy set variables */ // db table use $table = 'pedidos'; // table's primary key $primarykey = 'id'; // array of database columns should read , sent datatables. // db parameter represents column name in database, while dt // parameter represents datatables column identifier. in case simple // indexes $columns = array( array( 'db' => 'id', 'dt' => 0 ), array( 'db' => 'pedidos_data', 'dt' => 1, 'formatter' => function( $d, $row ) { return date( 'js m y', strtotime($d)); } ), array( 'db' => 'pedidos_nome', 'dt' => 2 ), array( 'db' => 'pedidos_cpf', 'dt' => 3 ), array( 'db' => 'pedidos_rg', 'dt' => 4 ), array( 'db' => 'pedidos_nascimento', 'dt' => 5 ), array( 'db' => 'pedidos_status', 'dt' => 6 ), ); // sql server connection information $sql_details = array( 'user' => 'root', 'pass' => '', 'db' => 'prevmaisaude', 'host' => 'localhost' ); /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * if want use basic configuration datatables php * server-side, there no need edit below line. */ require( 'ssp.class.php' ); echo json_encode( ssp::simple( $_get, $sql_details, $table, $primarykey, $columns ) );
what doing wrong?
Comments
Post a Comment