我有Angularjs
和CodeIgnitor
構建的應用程序。 angularjs設置$scope
數據使用$resource service在啓動時使用ng-init
獲取方法。打破JSON對象獲取
其做工精細用更少的數據,但應用程序無法與大數據計數。 GET響應中是否有任何數據大小限制,如GET參數限制?
錯誤:
Error: JSON.parse: end of data after property value in object
腳本:
app.factory('FamilyFind', ['$resource', 'Data', function ($resource, Data) {
return $resource(Data.rootUrl + 'admin/family_find/:id', {id: '@id'},
{
query: {
isArray: true,
method: 'GET'
},
update: {
method: 'PUT'
}
}
);
}]);
// load serverside data using http resource service
FamilyFind.get({}, function (response) { // success
$scope.tableData = response.data; // store result to variable
}, function (error) { // ajax loading error
Data.errorMsg(); // display custom error notification
// error caught here
});
我使用philsturgeon CodeIgnitor RESTful API用於後端服務。
CodeIgnitor控制器:
function family_find_get($id = '', $type = 'json') {
$this->response->format = $type;
$family = $this->family_registration_model->find($this->get());
if($family) { // success
$this->response(array('data' => $family), 200);
} else { // error
$this->response(array('data' => array()), 200);
}
}
CodeIgnitor型號:
function find($data) {
$query = "SELECT dev_members.name, dev_family.house_name, dev_family.house_no, dev_family.place,
dev_family.post, dev_family.phone,mem.male,mem.female
FROM dev_family
JOIN dev_members ON dev_members.id = dev_family.family_head_id
LEFT JOIN (SELECT family_id,SUM(gender = 'Male') AS male, SUM(gender = 'Female') AS female FROM dev_members) AS mem ON mem.family_id = dev_family.id WHERE dev_family.family_reg_no != ''";
if(isset($data['cluster']) && $data['cluster'] != '') {
$query.=" AND dev_family.cluster_id = ".$data['cluster']."";
}
$query = $this->db->query($query);
return $query->result();
}
編輯:
當調試從服務器端的響應時,它示出了主json對象不自動關閉LY。看到從500+記錄中提取的採樣數據,
{"data":[{"name":"abc","house_name":"dfdfgdfg","house_no":"1","place":"School Road","post":"dsfdfg","phone":"1111111","male":"278","female":"264"},{"name":"dgdfg","house_name":"dgdfg","house_no":"2","place":"School Road","post":"dfgdfg","phone":"111111","male":null,"female":null},{"name":"dgdfg","house_name":"dgdfg dgd","house_no":"3","place":"School Road","post":"dfgdg","phone":"11111","male":null,"female":null},{"name":"dgg","house_name":"dgdfg","house_no":"4","place":"School Road","post":"dggd","phone":"11111","male":null,"female":null}]
誤差在JSON格式器:
Error: Parse error on line 1:
...null,"female":null}]
-----------------------^
Expecting '}', ',', got 'EOF'
當我添加數據使用RESTClient實現附加在末尾}
物體接近,它工作正常。但我怎麼能在服務器端解決這個問題?爲什麼它只發生在大數據?
更新:
我已經意識到該問題是否與philsturgeon REST Controller library
。相反的,
$this->response(array('data' => $family), 200);
我都試過了,
echo json_encode(array('data'=>$family));
而現在它的工作fine.Anyone知道如何在philsturgeon REST Controller library
解決這個問題?
請參閱問題更新。 – devo