2

我有一个使用Angularjsand构建的应用程序CodeIgnitor。angularjs在启动时使用$resource 服务获取方法设置$scope数据,使用.ng-init

它在数据较少的情况下工作正常,但应用程序因大量数据而失败。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 对象没有自动关闭。查看从 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));

现在它工作正常。有人知道如何解决这个问题philsturgeon REST Controller library吗?

Github 问题在这里

4

1 回答 1

3

我认为问题不在于数据大小本身。响应通常不受限制(尽管有一些可能是由于操作时间过长或任何其他原因服务器关闭连接而客户端获取剪切数据)。

请更好地检查那里的数据是否正确。在我之前的经验中,我遇到了一些问题,当一些数据(通常是文本数据)带有一些特殊符号,如',',''','{','}'等可能被破坏。这取决于您的服务器端框架如何正确处理这些符号,以便客户端可以正确处理它。是否可以将输出打印到服务器端的日志中,并检查 JSON 数据是否正确。

于 2014-03-30T06:34:24.723 回答