I want to make a rest call to server using Angular but I am block I tried with traditional jQuery ajax call with Basic Authorization header looks something like this:
jQuery.ajax({
url: "http://localhost:8080/public/emp",
type: "GET",
dataType:"jsonp",
Accept : "application/json",
contentType: "application/json",
headers: {
'Authorization': 'Basic XXXXXXXXXXX'
},
success: function (data){
alert(data);
},
error: function(){
alert('Error');
}
});
It works perfectly and Data is retrieved.
But When I try to convert it with $http of AngularJs. Something like this:
$http({
method:'GET',
url : 'http://localhost:8080/public/emp',
headers: {'Authorization': 'Basic XXXXXXXXXX',"content-type":"application/json","Accept" : "application/json"}})
.success(function (data) {
alert("success");
})
.error(function (error) {
alert("error");
});
Its giving me Error 401 - Unauthorized
How can I add dataType property to $http? I have tried this link of stack overflow but Still unable to get a solution.