Getting invalid json response on data already populated in the table upon sorting

Getting invalid json response on data already populated in the table upon sorting

AdburyAdbury Posts: 4Questions: 1Answers: 1

On pageload the data is getting populated in ascending order. The once populated table when tried to sort by clicking on the arrow to the right of the column name "sr.no" throws "invalid json' error which makes no sense. cos the data is already populated and visible.

Below is the javascript code

var dTabel= $('#example').DataTable( {
"processing": true,
"serverSide": true,
"ajax": "includes/scripts/server_processing.php",
"pageLength": 100,
dom: "<'row'<'col-sm-3'l><'col-sm-3'f><'col-sm-6'p>>" +
"<'row'<'col-sm-12'tr>>" +
"<'row'<'col-sm-5'i><'col-sm-7'p>>",
columnDefs: [{
target: 10,
visible: false,
search:true
}]
} );`

Below is the php code

$primaryKey = 'srno';

$columns = array(
array( 'db' => 'srno', 'dt' => 0 ),
array( 'db' => 'std_name', 'dt' => 1 ),
array( 'db' => 'email', 'dt' => 2 ),
array( 'db' => 'mobile', 'dt' => 3 ),
array( 'db' => 'city', 'dt' => 4 ),
array( 'db' => 'Location', 'dt' => 5 ),
array( 'db' => 'school', 'dt' => 6 ),
array( 'db' => 'std', 'dt' => 7 ),
array( 'db' => 'refer', 'dt' => 8 ),
array( 'db' => 'caller', 'dt' => 9 ),
array( 'db' => 'manager', 'dt' => 10 ),
array(
'db' => 'registration_date',
'dt' => 11,
'formatter' => function( $d, $row ) {
return date( 'jS M y', strtotime($d));
}
)
)
require( 'ssp.class.php' );

echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);

The javascript library version

<script src='https://code.jquery.com/jquery-3.7.0.js'></script> <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/umd/popper.min.js" integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.min.js" integrity="sha384-0pUGZvbkm6XF6gxjEnlmuGrJXVbNuzT9qBBavbLwCsOGabYfZo0T0to5eqruptLy" crossorigin="anonymous"></script> <!-- Data Table JS --> <script src='https://cdn.datatables.net/1.13.5/js/jquery.dataTables.min.js'></script> <script src='https://cdn.datatables.net/responsive/2.1.0/js/dataTables.responsive.min.js'></script> <script src='https://cdn.datatables.net/1.13.5/js/dataTables.bootstrap5.min.js'></script>

Have attached a screenshot of the error that i get while sorting by column. If anybody could provide a solution or a reason for this I would be grateful. Thank you.

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,434Questions: 1Answers: 10,458 Site admin

    If it isn't valid JSON that it is returning, what does it return? I presume you followed the steps in the tech note the error message links to? Hopefully there will be an error message in there which would explain why the server-side script is failing.

    cos the data is already populated and visible.

    I'd suggest you read over this part of the manual which defines the difference between server-side and client-side processing. With server-side processing, just because one page is drawn, it doesn't mean the next will.

    Allan

  • AdburyAdbury Posts: 4Questions: 1Answers: 1
    edited March 19

    Thank you for your prompt response. I followed all the instructions as per the manuals. Its throwing this error on the last page which is 1147th. The response tab of the developer tools does not show any error as it is showing blank response. The data on that row in the database is fine as i checked it.

  • allanallan Posts: 63,434Questions: 1Answers: 10,458 Site admin
    Answer ✓

    it is showing blank response.

    That's invalid JSON - hence the error. The question is, why is the script returning an empty response!

    Try adding:

    error_reporting(\E_ALL);
    ini_set('display_errors', '1');
    

    At the top of the file (just inside the <?php tag). The server might be setup to suppress error messages (good for security).

    Allan

  • AdburyAdbury Posts: 4Questions: 1Answers: 1

    I tried printing error. Doesn't print anything. There is no error. Just that the query not returning any results. I tried printing the query being run where the array was blank. Then copied it and ran it through mysql admin. There is no problem with the query. Its returning a proper set of 100 rows. If there is anything else I should try please advice.

  • AdburyAdbury Posts: 4Questions: 1Answers: 1
    Answer ✓

    I found the error. Some special characters was inserted in the table. "•H•S•" this one to be exact. Thanks for the help. Have a gr8 day.

  • allanallan Posts: 63,434Questions: 1Answers: 10,458 Site admin

    Thanks for posting back. Good to hear you found the answer.

    Allan

Sign In or Register to comment.