Witam serdecznie, zarejestrowałem się na forum, gdyż chciałbym poprosić o pomoc. Mam problem z wyświetlaniem tabeli korzystając z datatables z server-side. Problem polega na tym, że tabela nie wyświetla się i zgłasza błąd: Invalid JSON Response i występuje, kiedy w bazie danych mam zaimportowane dane z polskimi i niemieckimi znakami. Ustawienia bazy i tabeli wybrane są na kodowanie UTF-8. W momencie, kiedy wyczyściłem tabelę w phpmyadmin i ręcznie pousuwałem polskie i niemieckie znaki z pliku CSV, który następnie importuję (dokładnie ten sam plik, tyle że bez "ogonków") wszystko działa poprawnie, tabela wyświetla się bez żadnych błędów. Jeżeli macie na to jakiś pomysł to bardzo bym prosił o pomoc, bo zupełnie nie wiem już gdzie szukać przyczyny. Domyślam się jedynie, że JSON nie ogarnia ogonków i nie pobiera danych, być może trzeba gdzieś wymusić kodowanie utf-8? Zamieszczam zrzuty plików. Z góry dziękuję
index.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=2.0">
<title></title>
<link rel="stylesheet" type="text/css" href="css/jquery.dataTables.css">
<link rel="stylesheet" type="text/css" href="css/shCore.css">
<link rel="stylesheet" type="text/css" href="css/demo.css">
<style type="text/css" class="init">
th, td { white-space: nowrap; }
div.dataTables_wrapper {
width: 800px;
margin: 0 auto;
}
</style>
<script type="text/javascript" language="javascript" src="js/jquery.js"></script>
<script type="text/javascript" language="javascript" src="js/jquery.dataTables.js" charset="utf-8"></script>
<script type="text/javascript" language="javascript" src="js/shCore.js"></script>
<script type="text/javascript" language="javascript" src="js/demo.js"></script>
<script type="text/javascript" language="javascript" class="init" charset="utf-8">
$(document).ready(function() {
$('#datatables').dataTable( {
"processing": true,
"serverSide": true,
"ajax": "js/server_processing.php"
} );
} );
</script>
</head>
<body class="dt-example">
<div class="container">
<table id="datatables" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Date 1</th>
<th>Date 2</th>
<th>Place</th>
<th>Book number</th>
<th>Location</th>
<th>Status</th>
<th>Country</th>
<th>Religion</th>
<th>Card ID</th>
<th>Description</th>
<th>Data 1</th>
<th>Data 2</th>
</tr>
</thead>
</table>
</div>
</body>
</html>
server-processing.php
<?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 <a href="http://datatables.net/usage/server-side" target="_blank">http://datatables.net/usage/server-side</a> for full details on the server-
* side processing requirements of DataTables.
*
* @license MIT - <a href="http://datatables.net/license_mit" target="_blank">http://datatables.net/license_mit</a>
*/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Easy set variables
*/
// DB table to use
$table = 'datatables';
// 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
array( 'db' => 'name', 'dt' => 0
), array( 'db' => 'date_1', 'dt' => 1
), array( 'db' => 'date_2', 'dt' => 2
), array( 'db' => 'place', 'dt' => 3
), array( 'db' => 'book', 'dt' => 4
), array( 'db' => 'location', 'dt' => 5
), array( 'db' => 'status', 'dt' => 6
), array( 'db' => 'country', 'dt' => 7
), array( 'db' => 'rel', 'dt' => 8
), array( 'db' => 'card_num', 'dt' => 9
), array( 'db' => 'desc', 'dt' => 10
), array( 'db' => 'data_1', 'dt' => 11
), array( 'db' => 'data_2', 'dt' => 12
), );
// SQL server connection information
'user' => 'root',
'pass' => 'psw',
'db' => 'datatables',
'host' => 'localhost'
);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 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' );
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);