我想在接收数据并将其存储后使用一个函数,但是无论如何我用我使用的代码都无法获得想要的结果。
有人可以向我提供有关我做错事情的详细信息吗?
我的代码:
$http({
method: 'GET',
url: 'JsonLocation'
}).then(
function successCallback(response) {
// this callback will be called asynchronously
// when the response is available.
self.responseData = response.data;
},
function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
console.log(response);
}
).then(
function completeCallback() {
// called when the http request is finished.
restyleData();
}
);
当页面被加载并且一切都设置到位时,我可以通过开发人员选项运行
restyleDate()
,然后它可以工作。但我只想在加载完所有内容后将其触发,而不是手动执行。 最佳答案
我建议更改为:
$http({
method: 'GET',
url: 'JsonLocation'
}).then(
function successCallback(response) {
// this callback will be called asynchronously
// when the response is available.
self.responseData = response.data;
// restyle is called after you save the result
restyleData();
},
function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
console.log(response);
}
);
关于javascript - http请求后调用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33354869/