我熟悉Jquery AJAX调用,它具有不同的回调函数,如beforeSend、success、complete等。
这是使用Jquery的示例AJAX调用:
$.ajax({
url: 'register.php',
type: 'POST',
data: {name:name, email:email},
beforeSend: function() {
// show loading GIF
},
complete: function() {
// hide loading GIF
},
success: function(data) {
// parse response
}
});
我希望使用AngularJS实现相同的功能。
在AngularJS的AJAX请求中是否有像beforeSend这样的回调函数? 这是我目前的代码,但我不确定在哪里可以使用类似beforeSend的回调函数(以便我可以显示加载GIF图像):
$http.post('register.php', {'name': $scope.name, 'email': $scope.email})
.success(function(data, status, headers, config) {
if (data != '') {
}
});
$httpProvider.responseInterceptors
已不再推荐使用。您应该提供一个带$httpProvider.interceptors
的样例。 - Satpal