I'm having a invalid Json response
I'm having a invalid Json response
The first thing I did has going to the link, that has in the alert, and I find out the Json response wasn't showing no data.
My debugger link: debug.datatables.net/ezaxig
My datatable code:
$(document).ready(function() {
$('#tabela').DataTable( {
"processing": true,
"serverSide": true,
"ajax": {
"url":"jsonp.php",
"dataType": "json",
"type": "GET"
},
"deferRender": true,
"columns": [
{ "data": "0" },
{ "data": "1" },
{ "data": "2" },
{ "data": "3" },
{ "data": "4" },
{ "data": "5" },
{ "data": "6" },
{ "data": "7" },
{ "data": "8" },
{ "data": "9" }
]
});
});
My Json code:
```
<?php
/*
* DataTables example server-side processing script.
*
* Please note that this script is intentionally extremely simply to show how
* server-side processing can be implemented, and probably shouldn't be used as
* the basis for a large complex system. It is suitable for simple use cases as
* for learning.
*
* See http://datatables.net/usage/server-side for full details on the server-
* side processing requirements of DataTables.
*
* @license MIT - http://datatables.net/license_mit
*/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Easy set variables
*/
// DB table to use
$table = 'empresas';
// Table's primary key
$primaryKey = 'id';
// Array of database columns which should be read and sent back to DataTables.
// The db
parameter represents the column name in the database, while the dt
// parameter represents the DataTables column identifier. In this case simple
// indexes
$columns = array(
array( 'db' => 'id', 'dt' => 0 ),
array( 'db' => 'nif', 'dt' => 1 ),
array( 'db' => 'nome', 'dt' => 2 ),
array( 'db' => 'morada', 'dt' => 3 ),
array( 'db' => 'distrito', 'dt' => 4 ),
array( 'db' => 'concelho', 'dt' => 5 ),
array( 'db' => 'freguesia', 'dt' => 6 ),
array( 'db' => 'localidade', 'dt' => 7 ),
array( 'db' => 'zip', 'dt' => 8 ),
array( 'db' => 'website', 'dt' => 9 )
);
$sql_details = array(
'user' => 'root',
'pass' => '',
'db' => 'shop_empresas',
'host' => 'localhost',
'charset' => 'utf8'
);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* If you just want to use the basic configuration for DataTables with PHP
* server-side, there is no need to edit below this line.
*/
require( 'ssp.class.php' );
echo json_encode(SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns ));
<?php
>
```
?>
I'm using uft-8 encoding in my database and using very portuguese words like "Irmãos"
This question has an accepted answers - jump to answer
Answers
What is the server responding with? The tech note that the error message links to tells you how you can find out that information.
Allan
Update - sorry, I missed the debugger link in your post. Thanks for that.
It shows that the server is not returning anything. That suggests there is an error happening in the server-side script. You will need to check your server's error logs to see what the error message is.
Allan
Thanks, @allan for responding.
I've found the problem, on function sql_ connect in the server side script.
I add "charset=utf8mb4" into the PDO in order to return "Irmãos".
And one more thing @allan, it was so hard to find the issue, could you somehow, highlight this problem, in order to help others
There are numerous reasons why the server might not be returning valid JSON. There can be no one-size-fits-all solution to that problem.