Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body ng-app="myApp">
  <div ng-controller="myController">
  <input type="button" value="Load" ng-click="load()">
    </div>
</body>
</html>
 
var myApp = angular.module("myApp",  []);
myApp.config(['$httpProvider', function ($httpProvider) {
    var $http,
        interceptor = ['$q', '$injector', function ($q, $injector) {
            function success(response) {
                // get $http via $injector because of circular dependency problem
                $http = $http || $injector.get('$http');
                if($http.pendingRequests.length < 1) {
                    console.log('ajax cal respond with success');
                }
                return response;
            }
            function error(response) {
              console.log('x', response);
                // get $http via $injector because of circular dependency problem
                $http = $http || $injector.get('$http');
                if($http.pendingRequests.length < 1) {
                    console.log('ajax call respond with error');
                }
                return $q.reject(response);
            }
            return function (promise) {
              console.log('before send ajax request');
                return promise.then(success, error);
            };
        }];
    $httpProvider.responseInterceptors.push(interceptor);
}]);
myApp.controller("myController", ["$scope", "$http", function($scope, $http) {
  $scope.load = function() {
    $http.get('http://openweathermap.org/data/2.3/forecast/city').success(function(data) {console.log(data);});
  };
}]);
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x