【发布时间】:2019-08-09 00:43:28
【问题描述】:
这是我在 stackoverflow.com 上的第一个问题: 过去我在这里找到了很多答案,但现在我遇到了一个我无法解决的问题: 我有一个项目,我使用 DataTables jquery 插件来显示来自简单 SQL 数据库的一些数据。 一切正常,但数据库已经有大约 18K 条目,所以速度很慢。我试图让 ajax 和服务器端处理工作,但我总是得到错误: "DataTables 警告:table id=tbl_portfolio - 无效的 JSON 响应。有关此错误的详细信息,请参阅http://datatables.net/tn/1"
我已经检查了链接,但我没有得到任何回应,所以我不能这样调试。 我阅读了很多内容并尝试了各种方法,但没有任何效果。
也许值得一提的是,DataTables 在 Wordpress 子主题中运行。
HTML 是:
<table id="tbl_portfolio" class="display nowrap" style="width:100%">
<thead>
<tr>
<th>URL</th>
<th>Themen</th>
<th>Keywords</th>
<th>Land</th>
<th>Kennzeichnung</th>
<th>Linkart</th>
<th>Ek Preis</th>
<th>Text inkl.</th>
<th>Text Preis</th>
<th>End Preis</th>
<th>Anmerkungen</th>
<th>Firma</th>
<th>Anrede</th>
<th>Vorname</th>
<th>Nachname</th>
<th>Strasse</th>
<th>Adresszusatz</th>
<th>PLZ</th>
<th>Ort</th>
<th>Land</th>
<th>eMail</th>
<th>Telefon</th>
</tr>
</thead>
<tfoot>
<tr>
<th>URL</th>
<th>Themen</th>
<th>Keywords</th>
<th>Land</th>
<th>Kennzeichnung</th>
<th>Linkart</th>
<th>Ek Preis</th>
<th>Text inkl.</th>
<th>Text Preis</th>
<th>End Preis</th>
<th>Anmerkungen</th>
<th>Firma</th>
<th>Anrede</th>
<th>Vorname</th>
<th>Nachname</th>
<th>Strasse</th>
<th>Adresszusatz</th>
<th>PLZ</th>
<th>Ort</th>
<th>Land</th>
<th>eMail</th>
<th>Telefon</th>
</tr>
</tfoot>
这是javascript部分:
// DB table to use
$table = 'portfolio_test';
// 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' => 'url', 'dt' => 0 ),
array( 'db' => 'themen', 'dt' => 1 ),
array( 'db' => 'keywords', 'dt' => 2 ),
array( 'db' => 'location', 'dt' => 3 ),
array( 'db' => 'kennzeichnung', 'dt' => 4 ),
array( 'db' => 'link_art', 'dt' => 5 ),
array( 'db' => 'preis_platz', 'dt' => 6 ),
array( 'db' => 'text_inkl', 'dt' => 7 ),
array( 'db' => 'preis_text', 'dt' => 8 ),
array( 'db' => 'preis_ek', 'dt' => 9 ),
array( 'db' => 'details', 'dt' => 10 ),
array( 'db' => 'firma', 'dt' => 11 ),
array( 'db' => 'anrede', 'dt' => 12 ),
array( 'db' => 'vorname', 'dt' => 13 ),
array( 'db' => 'nachname', 'dt' => 14 ),
array( 'db' => 'strasse', 'dt' => 15 ),
array( 'db' => 'adresszusatz', 'dt' => 16 ),
array( 'db' => 'plz', 'dt' => 17 ),
array( 'db' => 'ort', 'dt' => 18 ),
array( 'db' => 'land', 'dt' => 19 ),
array( 'db' => 'email', 'dt' => 20 ),
array( 'db' => 'telefon', 'dt' => 21 )
);
// SQL server connection information
$sql_details = array(
'user' => 'db_adm',
'pass' => '',
'db' => 'seo_metrics',
'host' => 'localhost:3306'
);
require 'ssp.class.php';
echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);
我正在使用来自https://github.com/DataTables/DataTablesSrc/blob/master/examples/server_side/scripts/ssp.class.php 的标准 ssp.class.php 文件
也许我在测试所有不同的东西时产生了一些新的错误,但我希望你们中的一些人能找到问题!
谢谢你们!
【问题讨论】:
-
将
echo json_encode替换为该方法调用返回的var_dump,直接通过浏览器地址栏调用脚本,启用完整且正确的错误报告……然后进行一些调试. -
您好 04FS,感谢您的快速答复!使用 var_dump 我得到一个数组作为响应。到目前为止看起来不错,它可以获取数据,但是我在数据库中有一些特殊字符,例如 Ö、Ä、Ü ... 这会导致错误吗?
-
这里是网站的链接:serply.de/serverside
-
好的,我已经按照您所写的...使用 var_dump 和直接调用脚本我看到了特殊字符。制作了一个没有它们的小型测试数据集,它工作正常!谢谢,这是一个很好的步骤!现在我尝试找出 ssp.class.php 文件中 utf8_encode 的位置。你能给我另一个提示来解决这个问题吗?太感谢了! :)
-
在调用@ 987654332@…?
标签: php json ajax datatables