? 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.
? 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.
$http.get(...)
.then(function(response){
//check response.status/headers/config/statusText
})
See: https://docs.angularjs.org/api/ng/service/ $ http
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);
});
}])
dies Siehe http://stackoverflow.com/questions/16532639/access-raw-xhr -object-using-http – GANI