由网友(心有所属。)分享简介:看着jQuery的文档,我发现了以下工作:Looking at the jQuery documentation I found out the following:$.get( "example.php", function() {alert( "success" );}).done(function() {a...
看着jQuery的文档,我发现了以下工作:
Looking at the jQuery documentation I found out the following:
$.get( "example.php", function() {
alert( "success" );
})
.done(function() {
alert( "second success" ); <---
})
.fail(function() {
alert( "error" );
})
.always(function() {
alert( "finished" );
});
我需要做一些Ajax调用,就像下面后执行的角度控制器的方法:
I need to execute a method in Angular controller after making few ajax calls, like following:
$q.all([
$http.get(ROOT + "Lookup/GetStates"),
$http.get(ROOT + "Lookup/GetCountries"),
$http.get(ROOT + "Address/GetAddresses"),
]).then(function (results) {
$scope.states = jQuery.parseJSON(results[0].data.data);
$scope.country = jQuery.parseJSON(results[1].data.data);
$scope.addresses = jQuery.parseJSON(results[3].data);
});
在然后
被执行(只有在当时的)我需要调用一个方法 $ scope.setupControls ()
after the then
gets executed (only after the then) I need to call a method $scope.setupControls()
时有没有可能呢?
推荐答案
有一看看这个:
.finally(function() {
// do this on both error and success
});
,因为它说,成功和错误后执行
As it says, executes after success and error
充满code:
$q.all([
$http.get(ROOT + "Lookup/GetStates"),
$http.get(ROOT + "Lookup/GetCountries"),
$http.get(ROOT + "Address/GetAddresses"),
]).then(function (results) {
$scope.states = jQuery.parseJSON(results[0].data.data);
$scope.country = jQuery.parseJSON(results[1].data.data);
$scope.addresses = jQuery.parseJSON(results[3].data);
}).finally(function() { /* <-- here */
// do this on both error and success
});
相关推荐
最新文章