I work on ionic. and got this error. Here are my app.js:
var app = angular.module('eMoMo', ['ionic', 'ngCordova'])
.config(['$httpProvider', function ($httpProvider) {
//Reset headers to avoid OPTIONS request (aka preflight)
$httpProvider.defaults.headers.common = {};
$httpProvider.defaults.headers.post = {};
$httpProvider.defaults.headers.get = {};
$httpProvider.defaults.headers.delete = {};
$httpProvider.defaults.headers.put = {};
$httpProvider.defaults.headers.patch = {};
$httpProvider.defaults.headers.common['Access-Control-Allow-Headers'] = '*';
//$httpProvider.defaults.headers.common['Authorization'] = 'Basic ' + btoa(my_id+ ':' + my_pass")
}]);
app.controller('MainViewController', function($scope, $http) {
$http({
method:"GET",
url: "my_url"
headers: {
'content-type': 'application/x-www-form-urlencoded; charset=utf-8',
'authorization': 'Basic ' + btoa('my_username' + ':' + 'my_pass')
'access-control-allow-origin': '*'
}
}).then(function(categories){
console.log(categories);
});
});
app.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
}
)
I try to research, it is relate about CORS but I have install an plugin to chrome to disable that error. How can I solve this problem. ?
401is Unathorized, probably the OPTIONS call is handled but since it has no authorization header it's rejected, you should handleOPTIONSto return200 OK- maurycy