我想向我的服务器发出HTTP请求,并且无法在我的问题上找到如何在jQuery样式中创建.always()
的答案。
根据Angular的$http
文档,只有这种结构:
// Simple GET request example :
$http.get('/someUrl').
then(function(response) {
// this callback will be called asynchronously
// when the response is available
}, function(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
答案 0 :(得分:2)
finally()
:
$http.get('/someUrl').
then(function(response) {
// this callback will be called asynchronously
// when the response is available
}.catch(error) {
// called asynchronously if an error occurs
// or server returns response with an error status.
}).finally() {
//Always do something
});
无论结果如何,总会被调用。
您可以在$q
here的文档中了解相关信息。