好的,我会尽量简明扼要。
错误可以在 http://www.hunterpdx.com/metro_new_copy/view-reports-test.php 处看到.
我在本地使用 DataTables-1.9.4,一切正常,但是一旦上传到我的主机服务器,我就会收到非常流行的 JSON 解析错误:
DataTables warning (table id = 'example'): DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error.
我在这里阅读了很多这些内容,并找到了很多很好的建议;主要是如何定位问题。我查看了 Chrome 开发工具上的“网络”选项卡,确定问题很简单:
Warning: mysql_pconnect() [function.mysql-pconnect]: Access denied for user 'username'@'localhost' (using password: NO) in /home/metros9/public_html/hunterpdx.com/metro_new_copy/server_processing.php on line 50
Warning: Cannot modify header information - headers already sent by (output started at /home/metros9/public_html/hunterpdx.com/metro_new_copy/server_processing.php:50) in /home/metros9/public_html/hunterpdx.com/metro_new_copy/server_processing.php on line 42 Could not open connection to server
在我看来,答案应该很简单:用户名或密码不正确。我的困惑(和问题)来自于它在本地运行良好,但不能实时运行。我使用 db.php 文件在我的实时站点上对多个 MySQL 查询使用相同的数据库连接信息,但由于某种原因,它不接受来自 server_processing.php 的相同信息。谁能告诉我为什么?我是新人,但很擅长解决问题......即使是关于其他要寻找的东西的一般方向也会非常感激!
服务器处理.php
/* 数据库连接信息 */
$gaSQL['user'] = "*****";
$gaSQL['password'] = "*****";
$gaSQL['db'] = "*****";
$gaSQL['server'] = "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
*/
/*
* Local functions
*/
function fatal_error ( $sErrorMessage = '' )
{
header( $_SERVER['SERVER_PROTOCOL'] .' 500 Internal Server Error' );
die( $sErrorMessage );
}
/*
* MySQL connection
*/
if ( ! $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) )
{
fatal_error( 'Could not open connection to server' );
}
if ( ! mysql_select_db( $gaSql['db'], $gaSql['link'] ) )
{
fatal_error( 'Could not select database ' );
}
最佳答案
变量被设置为 gaSQL,然后被称为 gaSql - 大小写不一致!
知道这很容易,但后悔花了多长时间才看到答案。
关于mysql - 数据表 JSON 解析错误 - 访问被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19063918/