JSON response validated ok, but receive Invalid JSON response.
JSON response validated ok, but receive Invalid JSON response.
https://drei.sieben4zehn5.de/minify/serverSideTest/**:
**Debugger code (debug.datatables.net): https://debug.datatables.net/anutib
Error messages shown: DataTables warning: table id=example - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1
Description of problem:
JSON response validated online ok, but receive Invalid JSON response message, this is my html
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link href="../../css/bootstrap-5.0.2-dist/css/bootstrap.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="../ext_assets/DataTables/datatables.css"/>
</head>
<body>
arbeitgeber | position |
---|---|
arbeitgeber | position |
</body>
</html>
and this the server-side script:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// DB table to use
$table = 'minify';
// Table's primary key
$primaryKey = 'id';
$columns = array(
array( 'db' => 'arbeitgeber', 'dt' => 0 ),
array( 'db' => 'position', 'dt' => 1 )
);
// SQL server connection information
$sql_details = array(
'user' => 'aer_talea',
'pass' => 'z&5T94jp',
'db' => 'web11573_talea-advisory',
'host' => 'localhost:3306'
);
require( 'ssp.class.php' );
echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);
thanks in advance
armin
This question has an accepted answers - jump to answer
Answers
In your browser use the network inspector to get the JSON response. In Chorme use the Response tab and copy the whole response. Paste it into https://jsonlint.com/ and you will find that it is not valid. The response as this at the end which makes it not valid:
Take a look at this JSONP example. The response looks like this:
I don't use PHP but if you look at the bottom of the script in teh Server-side Script tab you will see some additional code to handle the JSONP request. Looks like you might need to add that to your script.
Kevin
Hi Kevin, thanks, i included the two js-files:
and the json is valid, but still not working...
Solved this make it work:
$('#example').dataTable( { "processing": true, "serverSide": true, "ajax": { "url": "server_processing.php", "dataType": json" } } );
dataType json instead of jsonp
Regards Armin