15 AĞUSTOS 2012, ÇARŞAMBA
AngularJS ile hata işleyicisi küresel Ajax
Web siteme 100% jQuery iken, bunu yapmak için kullandım
$.ajaxSetup({
global: true,
error: function(xhr, status, err) {
if (xhr.status == 401) {
window.location = "./index.html";
}
}
});
401 hataları için küresel bir işleyicisi ayarlayın. Şimdi, $resource
$http
ile angularjs (DİNLENME) isteklerini yapmak için kullandığım sunucu. Benzer şekilde açısal ile genel hata işleyicisi ayarlamak için herhangi bir yolu var mı?
CEVAP
15 AĞUSTOS 2012, ÇARŞAMBA
Ayrıca açısal ile bir web sitesi inşa ediyorum ve küresel 401 kullanım için aynı engel ile karşılaştım. Bu blog yazısı rastladım http avcı ile sona erdi. Belki bunun gibi yararlı bulabilirsiniz.
"Authentication in AngularJS (or similar) based application.",espeo yazılım
EDİT: son çözüm
angular.module('myApp', ['myApp.filters', 'myApp.services', 'myApp.directives'], function ($routeProvider, $locationProvider, $httpProvider) {
var interceptor = ['$rootScope', '$q', function (scope, $q) {
function success(response) {
return response;
}
function error(response) {
var status = response.status;
if (status == 401) {
window.location = "./index.html";
return;
}
// otherwise
return $q.reject(response);
}
return function (promise) {
return promise.then(success, error);
}
}];
$httpProvider.responseInterceptors.push(interceptor);
Bunu Paylaş:
Nasıl bir WordPress kullanmak yakalama...
usta nasıl angularjs uı-router - app g...
jQuery ajax (jsonp) bir zaman aşımı yo...
ASP.NET MVC Ajax Hata işleme...
AngularJS : çağrılırken hata sindirimi...