我正在进行递归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行,在next中收到了下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);
如果响应数据是单个对象,那么你必须推送它
$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
。