我试图获取 >30,000 条记录作为 JSON 数据,我无法获得正确的响应。但我尝试了 PHP 服务 直接打印 JSON,它打印的是实际记录,没有任何错误。但是在 AngularJS 中,我无法获取实际的记录数。
我的示例 JSON 数据
{
"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
让我知道 Response
是否有任何限制?如何获取整个记录作为响应?请帮助我...
得到的Response Header Details
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
?>
Use the following PHP Script to test the task, it will produce the 35,000 records.
PHP 脚本:Statement.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
?>
用于获取记录的 AngularJS 示例脚本
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;
});
});
Note: I don't get any error, but I'm getting the partial output as a Response.
最佳答案
您将在内容本身之后发送 Content-Length header (并且该 header 不会出现在您列出的 header 详细信息中)。标题应该首先发送。也许这就是原因?
关于php - 如何在 AngularJS 和 PHP 中获取最大数量的 JSON 记录作为响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35329423/