这是一个
常见的问题,我已经研究了谷歌可以提供的所有答案,所以我很抱歉再次问它。
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
}
jsonlint.com 说 JSON 是有效的,但为什么 apache 将 Doctype 放在响应前面?这是导致错误的原因吗?
Firebug 还将标头报告为:
Connection Keep-Alive
Content-Length 798
Content-Type application/json
Date Wed, 23 Jan 2013 09:18:35 GMT
Keep-Alive timeout=5, max=100
Server Apache/2.2.22 (Ubuntu)
X-Powered-By PHP/5.4.6-1ubuntu1.1
我正在使用数据表中的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>
我已经浪费了很多时间试图解决这个问题,所以我非常感谢任何帮助。
我发现了我的问题。我有一个添加文档类型的前置函数。一旦删除,一切都很好。我通过将我的代码移动到另一个没有前缀的开发站点来找到它,它起作用了。