2017-07-06 102 views
0

我希望能够处理我的angularjs项目中的401状态码。我尝试了几种不同的响应拦截器,但是它们都返回-1的代码。我想了解为什么会发生这种情况。使用Angularjs v1.5.8。为什么Angularjs responseError拦截器返回状态码-1

myApp.factory('httpResponseInterceptor', function() { 
    return { 
    responseError: function (config) { 
     console.log(config.status); 
     //The above prints out -1 to the console 
     return config; 
    } 
    }; 
}); 

myApp.config(function ($httpProvider) { 
    $httpProvider.interceptors.push('httpResponseInterceptor'); 
}); 

回答

1

这是CORS问题,CORS是跨源资源共享。 您必须从服务器端启用CORS。