DataTables warning: JSON data from server could not be parsed. This is a caused by a JSON formatting error in Zend framework while using group

眉间皱痕 提交于 2019-12-11 06:18:20

问题


Please help me. I am stuck with one DataTable warning like "DataTables warning: JSON data from server could not be parsed. This is a caused by a JSON formatting error." in zend framework with PHP, JSON encode.

This warning only happens when the table is empty, But This problem is only coming when I use group keyword in sql query, If I do not use group keyword then it gives only one record from the table, but table have more records also. When I use the following query the output becomes, to show all records only the table have data, if not datatable warning will be shown.

// sql query (models/table/product.php)

 public function fetchAllProductItems() {
$oSelect = $this->select()
                ->setIntegrityCheck(false)
                ->from(array("p" => "products","b" => "bid"), ('*'))
                ->joinLeft(array("b" => "bid"), "b.product_id=p.product_id", array('bid_id','bid_amount'))
                ->joinInner(array("e" => "employees"), "e.employee_id=p.employee_id",array('ename'))
                ->where("p.verified = ?", "Yes")
                ->where("p.sold_out = ?", "No")
                ->group('p.product_id')
                ->having("p.sale_end_date >= ?", date("Y-m-d"));
        return $oSelect;

}

//JSON encode (Modules/sell/controllers/apicontroller)

public function getProductsAction()
{

     $oProductModel = new Application_Model_Db_Table_Products();
     $oSelect = $oProductModel->fetchAllProductItems();
     echo Zend_Json::encode($this->_helper->DataTables($oSelect, array('product_id','e.ename as employee_name','name', 'brand', 'conditions', 'about','image_path', 'reserved_price', 'Max(b.bid_amount) as amount')));

}

The below query will show only one record, if more than one records are having in the table. If the table is empty then I will come "No Data available in table message will come".

// sql query (models/table/product.php)

 $oSelect = $this->select()
                ->setIntegrityCheck(false)
                ->from(array("p" => "products","b" => "bid"), ('*'))
                ->joinLeft(array("b" => "bid"), "b.product_id=p.product_id", array('bid_id','bid_amount'))
                ->joinInner(array("e" => "employees"), "e.employee_id=p.employee_id",array('ename'))
                ->where("p.verified = ?", "Yes")
                ->where("p.sold_out = ?", "No")

                ->where("p.sale_end_date >= ?", date("Y-m-d"));

来源:https://stackoverflow.com/questions/42043094/datatables-warning-json-data-from-server-could-not-be-parsed-this-is-a-caused

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!