Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在HTML(Angularjs)上发布递归ajax调用数据_Html_Angularjs_Asynchronous - Fatal编程技术网

在HTML(Angularjs)上发布递归ajax调用数据

在HTML(Angularjs)上发布递归ajax调用数据,html,angularjs,asynchronous,Html,Angularjs,Asynchronous,我正在进行递归ajax调用并接收服务器数据。对于每个呼叫,我都会收到一些数据块。我想在前端显示这些数据。如何使每个接收到的数据部分都是一个低于另一个的。我希望这是清楚的 比如说 traceroute to 8.8.8.8 (8.8.8.8), 30 hops max, 60 byte packets 1 * * * 2 * * * 3 * * * 4 * * * 5 * * * 6 * * * 7 * * * 8 * * * 9 * * * 10 * * *

我正在进行递归ajax调用并接收服务器数据。对于每个呼叫,我都会收到一些数据块。我想在前端显示这些数据。如何使每个接收到的数据部分都是一个低于另一个的。我希望这是清楚的

比如说

traceroute to 8.8.8.8 (8.8.8.8), 30 hops max, 60 byte packets
 1  * * *
 2  * * *
 3  * * *
 4  * * *
 5  * * *
 6  * * *
 7  * * *
 8  * * *
 9  * * *
10  * * *
11  * * *
12  * * *
13  * * *
14  * * *
15  * * *
16  * * *
17  * * *
18  * * *
19  * * *
20  * * *
21  * * *
22  * * *
23  * * *
24  * * *
25  * * *
26  * * *
27  * * *
28  * * *
29  * * *
30  * * *
假设我在第一个ajax调用中收到前10行,在下一个调用中收到后5行,依此类推,我希望显示如上所示,而不删除第一个接收到的数据,并显示第二个接收到的数据。顺便说一下,我使用Angularjs作为前端

在Gaurav请求中添加了代码段

callOnReq(requestId);
            function callOnReq(requestId) {
                    console.log('Request ID sent')
                    $http.post('/py/recvData',{'requestId':requestId}).
                        success(function(data, status, headers, config) {
                            console.log('Data after request ID')
                            $scope.recdData data.output;
                            if (data.output != ""){
                                callOnReq(requestId);
                            }else if (data.output == ""){
                                console.log('Data receiving over');
                            }
                        }).
                        error(function(data, status, headers, config) {
                            console.log(status);
                        });
                };

提前感谢。

在作用域中声明一个变量

$scope.responseList=[];
然后将响应文本推到该位置

如果响应数据是列表,那么您必须将其关联起来

$scope.responseList=$scope.responseList.concat(data);
如果响应数据是单个objecth,则必须推送它

$scope.responseList.push(data);
示例代码

$http({
  // code
}).then(function(result){
   // data is list then you have to concate it 
   $scope.responseList=$scope.responseList.concat(data);
   // data is single objecth then you have to push it 
   $scope.responseList.push(data);
})

然后在视图中显示
responseList

为您目前拥有的内容发布一些代码