2016-09-23 30 views
0

? Gibt es eine Möglichkeit, auf xhr.responseURL mit angularjs $ http zuzugreifen?

Es gibt einen Artikel auf MDN erklärt, wie man mit roher xhr macht. Aber ich konnte keine Lösung für den Zugriff auf xhr-Objekt mit angularjs finden.

+0

dies Siehe http://stackoverflow.com/questions/16532639/access-raw-xhr -object-using-http – GANI

Antwort

1

ich eine Lösung durch Modifizierung der $ xhrFactory gefunden

angular.module('myApp', []) 
.factory('$xhrFactory', ['$rootScope', ($rootScope) => { 
    return function createXhr(method, url) { 

     // configure the xhr object that will be used for $http requests 
     const xhr = new window.XMLHttpRequest({ mozSystem: true }); 

     // attach an handler 
     xhr.onreadystatechange =() => { 
      if (xhr.readyState === XMLHttpRequest.DONE) { 

       /* 
       you can restrict local xhr calls 
       if (xhr.responseURL.startsWith('file://')) { 
        return; 
       } 
       */ 

       // broadcast xhr object to root scope 
       $rootScope.$broadcast('xhrDone', xhr); 
      } 
     }; 
     return xhr; 
    }; 
}]) 
.controller('MyCtrl', ['$scope', ($scope) => { 

    $scope.$on('xhrDone', (event, xhr) => { 
     // here is the responseURL 
     console.log(xhr.responseURL); 
    }); 

}]) 
Verwandte Themen