Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
DataTables json解析错误_Json_Datatables_Parsing Error - Fatal编程技术网

DataTables json解析错误

DataTables json解析错误,json,datatables,parsing-error,Json,Datatables,Parsing Error,这是一个常见的问题,我已经研究了谷歌能提供的所有答案,所以很抱歉再次问这个问题 Firebug将响应显示为 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> { "aaData" : [ [ "A", "0.67", "0.66", "0.66

这是一个常见的问题,我已经研究了谷歌能提供的所有答案,所以很抱歉再次问这个问题

Firebug将响应显示为

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

{ "aaData" : [ [ "A",
        "0.67",
        "0.66",
        "0.66",
        "0.66",
        "0.78",
        "1.52",
        "0.00",
        "0.00",
        "-15.38",
        "1970-01-01"
      ],
      [ "AA",
        "0.11",
        "0.12",
        "0.12",
        "0.14",
        "0.12",
        "-8.33",
        "0.00",
        "-14.29",
        "16.67",
        "2013-04-08"
      ],
      [ "AACC",
        "0.03",
        "0.04",
        "0.04",
        "0.04",
        "0.10",
        "-25.00",
        "0.00",
        "0.00",
        "-60.00",
        "2013-03-04"
      ],
      [ "AAN",
        "0.50",
        "0.50",
        "0.50",
        "0.50",
        "0.49",
        "0.00",
        "0.00",
        "0.00",
        "2.04",
        "2013-02-04"
      ],
      [ "AAON",
        "0.23",
        "0.23",
        "0.22",
        "0.22",
        "0.20",
        "0.00",
        "4.55",
        "0.00",
        "10.00",
        "2013-03-11"
      ],
      [ "AAP",
        "0.76",
        "0.76",
        "0.76",
        "0.76",
        "0.76",
        "0.00",
        "0.00",
        "0.00",
        "0.00",
        "2013-02-07"
      ],
      [ "AAPL",
        "13.42",
        "13.34",
        "13.30",
        "13.34",
        "15.45",
        "0.60",
        "0.30",
        "-0.30",
        "-13.66",
        "2013-01-    23"
      ]
    ],
  "iTotalDisplayRecords" : "7",
  "iTotalRecords" : "7",
  "sEcho" : 1
}
我正在使用DataTables中的server_processing.php脚本

header('Content-Type: application/json');
echo $output;
我的php的相关部分是:

    $(document).ready(function() {
                $('#example').dataTable( {
                    "bProcessing": true,
                    "bServerSide": true,
                    "sAjaxSource": "server_processing.php",
                    "sPaginationType": "full_numbers"
                } );
            } );
        </script>
    </head>
    <body>
    <div id="dynamic">
    <table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
    <thead>
        <tr>
            <th>Symbol</th>
            <th>Current Estimate</th>
            <th>7 days ago</th>
            <th>30 days ago</th>
            <th>60 days ago</th>
            <th>90 days ago</th>
            <th>% Change Current</th>
            <th>% Change 7</th>
            <th>% Change 30</th>
            <th>% Change 60</th>
            <th>Next Earnings Date</th></th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td colspan="10" class="dataTables_empty">Loading data from server</td>
        </tr>
    </tbody>
    <tfoot>
        <tr>
            <th>Symbol</th>
            <th>Current Estimate</th>
            <th>7 days ago</th>
            <th>30 days ago</th>
            <th>60 days ago</th>
            <th>90 days ago</th>
            <th>% Change Current</th>
            <th>% Change 7</th>
            <th>% Change 30</th>
            <th>% Change 60</th>
        </tr>
    </tfoot>
   </table>
$(文档).ready(函数(){
$('#示例')。数据表({
“bProcessing”:正确,
“bServerSide”:正确,
“sAjaxSource”:“server_processing.php”,
“sPaginationType”:“完整编号”
} );
} );
象征
当前估计数
7天前
30天前
60天前
90天前
%变流
%变化7
%更改30
%更改60
下一个盈利日期
从服务器加载数据
象征
当前估计数
7天前
30天前
60天前
90天前
%变流
%变化7
%更改30
%更改60

我花了很多时间试图解决这个问题,因此非常感谢您的帮助。

我发现了我的问题。我有一个prepend函数,用于添加doctype。一旦移除,一切都很好。我通过将代码移动到另一个没有前置码的开发站点找到了它,它成功了。

您收到了什么错误消息?抱歉,应该包括:DataTables警告(table id='example'):DataTables警告:无法解析来自服务器的JSON数据。这是由JSON格式错误引起的。另外,如果我将json输出保存为文本文件,它将非常有效。反斜杠不能解决问题,既然响应是有效的json,为什么还需要反斜杠呢?从文本文件读取时,没有doctype头,并且接受json。服务器的输出包括doctype(见上文)。我相信我需要在PHP或Apache2中抑制doctype,但还没有找到这样做的方法。
    $(document).ready(function() {
                $('#example').dataTable( {
                    "bProcessing": true,
                    "bServerSide": true,
                    "sAjaxSource": "server_processing.php",
                    "sPaginationType": "full_numbers"
                } );
            } );
        </script>
    </head>
    <body>
    <div id="dynamic">
    <table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
    <thead>
        <tr>
            <th>Symbol</th>
            <th>Current Estimate</th>
            <th>7 days ago</th>
            <th>30 days ago</th>
            <th>60 days ago</th>
            <th>90 days ago</th>
            <th>% Change Current</th>
            <th>% Change 7</th>
            <th>% Change 30</th>
            <th>% Change 60</th>
            <th>Next Earnings Date</th></th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td colspan="10" class="dataTables_empty">Loading data from server</td>
        </tr>
    </tbody>
    <tfoot>
        <tr>
            <th>Symbol</th>
            <th>Current Estimate</th>
            <th>7 days ago</th>
            <th>30 days ago</th>
            <th>60 days ago</th>
            <th>90 days ago</th>
            <th>% Change Current</th>
            <th>% Change 7</th>
            <th>% Change 30</th>
            <th>% Change 60</th>
        </tr>
    </tfoot>
   </table>