I have a RESTful back-end server enabling the basic authentication. I would like to implement a GET request in my angularJS file to get some data from the server.
Code:
angular.module('MyApp', [])
.controller('MyCtrl',function ($scope, $http) {
var userheader= btoa('username' + ':' + 'userpassword');
$scope.getData= function (){
var req = {
method: 'GET',
url: 'https://localhost:8000/data/',
headers: { 'Authorization': 'Basic ' + userheader }
};
$http(req)
.success(function(data) {
$scope.mydata = data;
}).error(function(){
throw new Error('Somthing went wrong');
});
};
});
When I invoked the function 'getData()', it always give me the error "No 'Access-Control-Allow-Origin' header is present on the requested resources".
Aucun commentaire:
Enregistrer un commentaire