[英]Ajax from php DataTables warning:table id=example - Invalid JSON response
<!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <head> <meta charset="GBK"> <title></title> </head> <body> {"sEcho":1,"iTotalRecords":1,"iTotalDisplayRecords":1,"aaData":[["086671","NB","MSC-1","09-APR-15"],["086673","DB","MSC-2","09-APR-15"],["086678","DA","MSC-1","10-APR-15"],["086682","DA","MSC-1","10-APR-15"],["086683","NA","MSC-1","10-APR-15"],["086491","NA","MSC-2","25-MAR-15"],["086686","DA","MSC-1","10-APR-15"],["086688","DA","MSC-2","10-APR-15"],["086690","NA","MSC-2","10-APR-15"],["086496","DA","MSC-1","25-MAR-15"],["086685","NB","MSC-1","09-APR-15"],["086848","NA","MSC-2","22-APR-15"],["086516","NA","MSC-1","22-APR-15"],["086523","DA","MSC-1","22-APR-15"],["086839","DA","MSC-2","22-APR-15"],["086849","DA","MSC-1","22-APR-15"],["086528","NB","MSC-1","24-APR-15"],["086526","NB","MSC-1","27-MAR-15"],["086478","DA","MSC-1","25-MAR-15"],["086482","DB","MSC-1","27-MAR-15"],["086832","NB","MSC-1","24-APR-15"],["086840","DB","MSC-2","24-APR-15"],["086842","NB","MSC-2","24-APR-15"],["086828","DB","MSC-1","24-APR-15"],["086987","NB","MSC-1","07-MAY-15"],["086991","DB","MSC-2","07-MAY-15"]]} </body> </html>
I am a new-comer to php and jQuery, now I have one question; 我是php和jQuery的新手,现在我有一个问题。 when I use a datatable to query data, error as title, and detail code as follows: 当我使用数据表查询数据,错误作为标题和详细代码时,如下所示:
html: HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="GBK">
<title>作业</title>
<link href="http://CEA815099W/test/cim_web/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="http://Cea815099w/test/cim_web/css/dataTables.bootstrap.css" />
<script src="http://CEA815099W/test/cim_web/js/jquery-1.11.3.min.js"></script>
<script src="http://CEA815099W/test/cim_web/js/jquery.dataTables.min.js"></script>
<script src="http://CEA815099W/test/cim_web/js/dataTables.bootstrap.js"></script>
<script src="http://CEA815099W/test/cim_web/js/echarts.js"></script>
<script src="http://CEA815099W/test/cim_web/js/bootstrap.min.js">
</head>
<body>
<!-- table-->
<div class="container">
<table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>工号</th>
<th>班别</th>
<th>站点</th>
<th>时间</th>
</tr>
</thead>
<tbody>
<!-- js处理数据库内容-->
</tbody>
<tfoot>
<tr>
<th>工号</th>
<th>班别</th>
<th>站点</th>
<th>时间</th>
</tr>
</tfoot>
</table>
</div>
</body>
</html>
Javascript: 使用Javascript:
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"sAjaxSource": "data.php"
} );
} );
</script>
<script type="text/javascript">
// For demo to fit into DataTables site builder...
$('#example')
.removeClass( 'display' );
.addClass('table table-striped table-bordered');
</script>
PHP: PHP:
<?php
$db = new PDO("oci:dbname=mfdm10", "f10mfg",'demon');
$db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_WARNING); // 设置为警告模式
$rs = $db->prepare("select a.empid,a.shift,a.station,a.infab_time from ut_msc_newcoming a where rownum <= :num"); // SQL 需要修改
$rs->bindValue(':num', 26);
$rs->execute();
while($row=$rs->fetch()){
$data[]= array(
$row[0],
$row[1],
$row[2],
$row[3]
);
}
/* $output = array(
"sEcho" => 1,
"iTotalRecords" => count($row),
"iTotalDisplayRecords" => count($row),
"aaData" => $data
); */
$response = array();
$response['success'] = true;
$response['aaData'] = $data;
echo json_encode( $response );
//异常
function fatal($msg)
{
echo json_encode(array(
"error" => $msg
));
exit(0);
}
?>
Add my json returning from network of the console 添加我从控制台网络返回的json
<!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <head> <meta charset="GBK"> <title></title> </head> <body> {"success":true,"aaData":[["086671","NB","MSC-1","09-APR-15"],["086673","DB","MSC-2","09-APR-15"],["086678","DA","MSC-1","10-APR-15"],["086682","DA","MSC-1","10-APR-15"],["086683","NA","MSC-1","10-APR-15"],["086491","NA","MSC-2","25-MAR-15"],["086686","DA","MSC-1","10-APR-15"],["086688","DA","MSC-2","10-APR-15"],["086690","NA","MSC-2","10-APR-15"],["086496","DA","MSC-1","25-MAR-15"],["086685","NB","MSC-1","09-APR-15"],["086848","NA","MSC-2","22-APR-15"],["086516","NA","MSC-1","22-APR-15"],["086523","DA","MSC-1","22-APR-15"],["086839","DA","MSC-2","22-APR-15"],["086849","DA","MSC-1","22-APR-15"],["086528","NB","MSC-1","24-APR-15"],["086526","NB","MSC-1","27-MAR-15"],["086478","DA","MSC-1","25-MAR-15"],["086482","DB","MSC-1","27-MAR-15"],["086832","NB","MSC-1","24-APR-15"],["086840","DB","MSC-2","24-APR-15"],["086842","NB","MSC-2","24-APR-15"],["086828","DB","MSC-1","24-APR-15"],["086987","NB","MSC-1","07-MAY-15"],["086991","DB","MSC-2","07-MAY-15"]]} </body> </html>
My original json returning, any error? 我的原始json返回了,有什么错误吗?
On this page in the documentation it states the following: 在文档的此页面上,它指出以下内容:
Reply from the server 服务器回复
In reply to each request for information that DataTables makes to the server, it expects to get a well formed JSON object with the following parameters.... 作为对DataTables向服务器发出的每个信息请求的答复,它希望获得具有以下参数的格式正确的JSON对象。
It does not appear that your are setting these variables and this may the reason for the error message "warning:table id=example - Invalid JSON response" as your JSON, while valid JSON, is not a valid "JSON response" related to what datatables expects. 似乎您没有设置这些变量,这可能是错误消息“警告:表id = example-无效的JSON响应”作为您的JSON的原因,而有效的JSON并不是与之相关的有效的“ JSON响应”数据表的期望。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.