DataTables警告:无法解析来自服务器的JSON数据。这是由使用组时Zend框架中的JSON格式错误引起的

时间:2017-02-04 17:06:03

标签: json zend-framework datatable

请帮帮我。我遇到了一个DataTable警告,例如“ DataTables警告:来自服务器的JSON数据无法解析。这是由jSON格式错误引起的。”在zend框架中使用PHP,JSON编码。

此警告仅在表为空时发生,但此问题仅在我在sql查询中使用group关键字时出现,如果我不使用group关键字,那么它只从表中提供一条记录,但表有更多记录也。 当我使用以下查询输出时,显示所有记录只有表有数据,如果没有数据表警告将显示。

// 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编码(模块/出售/控制器/ 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')));

}

如果表中有多个记录,则下面的查询将只显示一条记录。如果表是空的,那么我将“来自表格消息中没有数据可用”。

// 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"));

0 个答案:

没有答案