Php 在Zend框架中处理jquery数据表的服务器端
我正在尝试使用数据表和服务器端处理。这是我的看法:Php 在Zend框架中处理jquery数据表的服务器端,php,jquery,zend-framework,datatables,server-side,Php,Jquery,Zend Framework,Datatables,Server Side,我正在尝试使用数据表和服务器端处理。这是我的看法: <table id="datatables" class="display"> <thead> <tr> <th>Your Name</th> <th>Date and Time</th> <th>Actions</th> </tr> </thead>
<table id="datatables" class="display">
<thead>
<tr>
<th>Your Name</th>
<th>Date and Time</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script>
$(document).ready( function () {
// DATATABLES CONFIGURATION
$('#datatables').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "results/loadReportsAction"
} );
});
</script>
如您所见,我只是尝试加载字符串,如“test”、“test2”我首先要使数据加载正确,然后创建过滤、排序等 当我加载此文件时,只会出现以下错误: DataTables警告(表id='DataTables'):DataTables警告:无法解析来自服务器的JSON数据。这是由JSON格式错误引起的 这就是我的回答: 或者检查一下 他只显示现有的HTML,而不显示已发送的json。有一个操作助手可以输出json,它将处理禁用布局和以json格式发送具有正确标题的数据 我没有发现你的代码有任何错误,但我建议你这样做
<table id="datatables" class="display">
<thead>
<tr>
<th>Your Name</th>
<th>Date and Time</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script>
$(document).ready( function () {
// DATATABLES CONFIGURATION
$('#datatables').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "results/load-reports"// Change this line
} );
});
</script>
public function loadReportsAction() {
$this->_helper->layout->disableLayout();// Comment this line
$this->_helper->viewRenderer->setNoRender();// Comment this line
$row = array();
$output = array(
"iTotalRecords" => 34,
"iTotalDisplayRecords" => 34,
"aaData" => array()
);
$sessions = SessionQuery::create()->findByQuizId(3);
foreach($sessions as $session){
$row[] = "test";
$row[] = "test2";
$row[] = "test3";
$output['aaData'][] = $row;
$row = array();
}
echo json_encode( $output );// Comment this line
$this->_helper->json->sendJson($output);
}
你的名字
日期和时间
行动
$(文档).ready(函数(){
//数据表配置
$('#datatables')。dataTable({
“bProcessing”:正确,
“bServerSide”:正确,
“sAjaxSource”:“结果/加载报告”//更改此行
} );
});
公共函数loadReportsAction(){
$this->_helper->layout->disableLayout();//注释此行
$this->_helper->viewRenderer->setNoRender();//注释此行
$row=array();
$output=array(
“iTotalRecords”=>34,
“iTotalDisplayRecords”=>34,
“aaData”=>array()
);
$sessions=SessionQuery::create()->findByQuizId(3);
foreach($sessions作为$session){
$row[]=“测试”;
$row[]=“test2”;
$row[]=“test3”;
$output['aaData'][]=$row;
$row=array();
}
echo json_encode($output);//注释此行
$this->\u helper->json->sendJson($output);
}
有一个用于输出json的操作助手,它将处理禁用布局和以json格式发送数据,并带有正确的标题
我没有发现你的代码有任何错误,但我建议你这样做
<table id="datatables" class="display">
<thead>
<tr>
<th>Your Name</th>
<th>Date and Time</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script>
$(document).ready( function () {
// DATATABLES CONFIGURATION
$('#datatables').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "results/load-reports"// Change this line
} );
});
</script>
public function loadReportsAction() {
$this->_helper->layout->disableLayout();// Comment this line
$this->_helper->viewRenderer->setNoRender();// Comment this line
$row = array();
$output = array(
"iTotalRecords" => 34,
"iTotalDisplayRecords" => 34,
"aaData" => array()
);
$sessions = SessionQuery::create()->findByQuizId(3);
foreach($sessions as $session){
$row[] = "test";
$row[] = "test2";
$row[] = "test3";
$output['aaData'][] = $row;
$row = array();
}
echo json_encode( $output );// Comment this line
$this->_helper->json->sendJson($output);
}
你的名字
日期和时间
行动
$(文档).ready(函数(){
//数据表配置
$('#datatables')。dataTable({
“bProcessing”:正确,
“bServerSide”:正确,
“sAjaxSource”:“结果/加载报告”//更改此行
} );
});
公共函数loadReportsAction(){
$this->_helper->layout->disableLayout();//注释此行
$this->_helper->viewRenderer->setNoRender();//注释此行
$row=array();
$output=array(
“iTotalRecords”=>34,
“iTotalDisplayRecords”=>34,
“aaData”=>array()
);
$sessions=SessionQuery::create()->findByQuizId(3);
foreach($sessions作为$session){
$row[]=“测试”;
$row[]=“test2”;
$row[]=“test3”;
$output['aaData'][]=$row;
$row=array();
}
echo json_encode($output);//注释此行
$this->\u helper->json->sendJson($output);
}
谢谢!但我仍然会在更改代码时遇到相同的错误。你知道我如何用javascript检查返回的json吗?如果你有firebug,你可以很容易地做到这一点。打开firebug网络面板,查看发送了什么请求。如果您没有使用post方法,请右键单击请求,然后单击“在新选项卡中打开响应”,如果json输出正确,则问题出现在您的前端,否则问题出现在服务器端代码中,添加带有问题的响应屏幕截图单击“响应”选项卡我正在预览tab@nielsv现在检查并更改您的密码sAjaxSource Variable谢谢!但我仍然会在更改代码时遇到相同的错误。你知道我如何用javascript检查返回的json吗?如果你有firebug,你可以很容易地做到这一点。打开firebug网络面板,查看发送了什么请求。如果您没有使用post方法,请右键单击请求,然后单击“在新选项卡中打开响应”,如果json输出正确,则问题出现在您的前端,否则问题出现在服务器端代码中,添加带有问题的响应屏幕截图单击“响应”选项卡我正在预览tab@nielsv现在检查并更改您的密码SAJAX源变量