gpt4 book ai didi

javascript - 如何等待 Angular http方法完成

转载 作者:行者123 更新时间:2023-11-30 07:58:35 25 4
gpt4 key购买 nike

这是我从服务器获取数据的函数

function getAll_Tables() {
$scope.tableList = [];
$http({
method : 'GET',
url : '/abc/GetTables',
headers : {'Content-Type' : 'application/json'}
}).success(function(data) {
$('#T_LoaderSpinner').hide();
if (data.StatusCode === 101) {
if (data.Data != null) {
for (var i = 0; i < data.Data.length; i++) {
$scope.tableList.push(data.Data[i]);
}
}
} else {
alert("We could not process your request......Please try later.")
}
})
.error(function(data) {
$('#T_LoaderSpinner').hide();
alert("We could not process your request......Please try later.")
});
}

我使用该数据的另一个功能是:

$scope.load_policy = function(id, type) {
$scope.getRuleList();
getAll_ScoringTables();
alert(JSON.stringify($scope.tableList));
}

我的 tableList 没有更新 - 如何在这里更新 tableList?

最佳答案

这里有一个更舒服的方式,使用促销

var promise1 = $http({method: 'GET', url: 'a/pi-one-url', cache: 

'true'});
var promise2 = $http({method: 'GET', url: '/api-two-url', cache: 'true'});

$q.all([promise1, promise2]).then(function(data){
console.log(data[0], data[1]);
});

关于javascript - 如何等待 Angular http方法完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33806567/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com