I am using http dependency in angularjs and setting headers for CORS but still getting following error. Please go through console.log you will see following error.
XMLHttpRequest cannot load https://blockchain.info/tobtc?currency=INR&value=1000&cors=true. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8080' is therefore not allowed access.
If you go through by this URL, you will get to know that it allows CORS https://blockchain.info/api/exchange_rates_api
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<input type = "button" id ="btcButton" value = "Convert" ng-click= "currencytoBtc()" />
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope,$http,$q) {
$scope.currencytoBtc = function(){
var a = $scope.currency;
var b = $scope.currencyInput;
console.log(a);
console.log(b);
$http({method: 'GET', url: 'https://blockchain.info/tobtc?currency=INR&value=1000&cors=true',
headers:{
'Access-Control-Allow-Origin': '*',
'Content-Type': 'text/plain;charset=UTF-8',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With'
}})
.then(function(d){ console.log( "yay",d ); })
.catch(function(d){ console.log( "nope" ); });
}
});
</script>
</body>
</html>
https://blockchain.info/tobtc?currency=INR&value=1000looks like they don't send CORS headers, because they don't want you to "borrow" their resources - not sure where you got the idea of addingcors=truerequest parameter, but it doesn't do anything - Jaromanda X