@H_404_2@
我正在尝试将使用jQuery编写的模块转换为AngularJS.
我有一个ajaxSuccess和ajaxError处理程序,它在全局级别执行ajax响应处理.它负责显示所有ajax请求中的成功/失败消息.
AngularJS中是否有相同的功能?
我已经通过$http服务,但没有找到任何解决方案.
解决方法
你可以通过拦截器实现这一目标.例:
myapp.config(function($httpProvider) { var myInterceptor = ['$rootScope','$q',function(scope,$q) { function onSuccess(response) { return response; } function onError(response) { return $q.reject(response); } return function(promise) { return promise.then(onSuccess,onError); }; }]; $httpProvider.responseInterceptors.push(myInterceptor); });
@H_404_2@