如何在AngularJS和PHP中获取最大数量的JSON记录作为响应
我试图以JSON数据的形式获取30000条记录,但无法获得正确的响应。但是我尝试了PHP服务直接打印JSON,它打印实际记录时没有任何错误。但在AngularJS中,我无法获取实际记录数 我的示例JSON数据如何在AngularJS和PHP中获取最大数量的JSON记录作为响应,php,angularjs,json,http-headers,httpresponse,Php,Angularjs,Json,Http Headers,Httpresponse,我试图以JSON数据的形式获取30000条记录,但无法获得正确的响应。但是我尝试了PHP服务直接打印JSON,它打印实际记录时没有任何错误。但在AngularJS中,我无法获取实际记录数 我的示例JSON数据 { "records":[ { "ldat":"2014-08-13", "eid":"HSL018", "dr":"55420", "cr":"0", "bal":"55420"
{
"records":[
{
"ldat":"2014-08-13",
"eid":"HSL018",
"dr":"55420",
"cr":"0",
"bal":"55420"
},
{
"ldat":"2014-10-11",
"eid":"HBL056",
"dr":"0",
"cr":"35000",
"bal":"20420"
},
{
"ldat":"2014-10-26",
"eid":"HBL001",
"dr":"0",
"cr":"420",
"bal":"20000"
},
----- 30,000 Records -----
,
{
"ldat":"2015-11-01",
"eid":"HDL001",
"dr":"0",
"cr":"20000",
"bal":"0"
}
]
}
在调试时,我只从响应中得到部分输出
{
"records":[
{
"ldat":"2014-08-13",
"eid":"HSL018",
"dr":"55420",
"cr":"0",
"bal":"55420"
},
{
"ldat":"2014-10-11",
"eid":"HBL056",
"dr":"0",
"cr":"35000",
"bal":"20420"
},
{
"ldat":"2014-10-26",
"eid":"HBL001",
"dr":"0",
"cr":"420",
"bal":"20000"
},
----- 4,000 Records -----
,
{
"ldat":"2015-11-01",
"eid":"HDL0
让我知道响应中是否存在任何限制
?如何获取整个记录作为响应?请帮助我
我得到的响应标题详细信息
HTTP/1.1 200 OK
Date: Thu, 11 Feb 2016 01:31:45 GMT
Server: Apache
Access-Control-Allow-Origin: *
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Vary: Accept-Encoding
Content-Encoding: gzip
Keep-Alive: timeout=10, max=500
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: application/json; charset=UTF-8
我的PHP服务脚本
<?php
ob_start(); // start normal buffer
ob_start("ob_gzhandler"); // start gzip buffer
echo $content;
ob_end_flush(); // output gzipped content
$gzippedContent = ob_get_contents(); // store gzipped content to get size
header('Content-Length: '.strlen($gzippedContent));
ob_end_flush(); // flush gzipped content
?>
注意:我没有得到任何错误,但是我得到的是部分输出
答复
30k结果似乎是一个非常大的结果集。你真的需要所有这些数据吗?你能把结果分页吗
如果您可以在浏览器中看到没有Angular的json,我怀疑问题来自Angular或您的web浏览器。太多数据无法检索,可能会冻结浏览器。Chrome提供了监控浏览器的强大工具,可以尝试查看您是否达到浏览器限制。您将在内容本身之后发送内容长度标题(并且该标题不会出现在您列出的标题详细信息中)。应首先发送标题。也许这就是原因?这可能有助于您粘贴得到的错误。@oseintow没有语义错误。由于响应的内容长度,我无法获得实际记录。当它不起作用时会发生什么?如果你不能得到正确的响应,这不会是一个角度上的问题。您要么没有清楚地描述问题,要么这是php方面的问题。您能在网络选项卡中看到正确的响应吗?
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
$content = "";
for($i=1; $i<=35000; $i++) {
if ($content != "") {
$content .= ",";
}
$content .= '{"slr":' . $i . ',';
$content .= '"uid":' . rand(100,10000) . ',';
$content .= '"name":"Balamanigandan",';
$content .= '"cell":"9999999999",';
$content .= '"balance":10000,';
$content .= '"ltrans":"2015-01-01",';
$content .= '"msg":" Opening Balance"}';
}
$content = '{"records":[' . $content . ']}';
ob_start(); // start normal buffer
ob_start("ob_gzhandler"); // start gzip buffer
echo $content;
ob_end_flush(); // output gzipped content
$gzippedContent = ob_get_contents(); // store gzipped content to get size
header('Content-Length: '.strlen($gzippedContent));
ob_end_flush(); // flush gzipped content
?>
var stmt= angular.module('Statement', []);
stmt.controller('StmtCtrl', function($scope, $http, $cacheFactory) {
var request = $http({
method: "post",
url: "Statement.php",
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
});
request.success(function (response)
{
$scope.data = response;
});
});